Esempio n. 1
0
File: add.go Progetto: jzorn/grnl
			fmt.Println("Nothing saved")
			os.Exit(0)
		}

		newEntry := entry.New()
		newEntry.Parse(input, dateFormat)

		dbContents, readFileErr := ioutil.ReadFile(db)
		if readFileErr != nil {
			if !os.IsNotExist(readFileErr) {
				fmt.Println(readFileErr)
				os.Exit(1)
			}
		}

		grnl, err := journal.FromJson(dbContents)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		grnl.Add(*newEntry)
		grnlJson, err := grnl.ToJson()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		if err := ioutil.WriteFile(db, grnlJson, 0600); err != nil {
			if !os.IsNotExist(err) {
				fmt.Println(err)
Esempio n. 2
0
File: list.go Progetto: jzorn/grnl
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "Displays your last journal entries",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		dbFile := viper.GetString("db")

		dbContents, readFileErr := ioutil.ReadFile(dbFile)
		if readFileErr != nil {
			if !os.IsNotExist(readFileErr) {
				fmt.Println(readFileErr)
				os.Exit(1)
			}
		}

		grnl, fromJsonErr := journal.FromJson(dbContents)
		if fromJsonErr != nil {
			fmt.Println(fromJsonErr)
			os.Exit(1)
		}

		if tags != "" {
			grnl = grnl.WithSomeTags(strings.Split(tags, ","))
		}

		if onString != "" {
			on, onErr := time.Parse(DateFormat, onString)
			if onErr != nil {
				fmt.Println("Cannot parse --on date: ", onErr)
			}