diff --git a/commands.go b/commands.go index 1549682..4d07d6f 100644 --- a/commands.go +++ b/commands.go @@ -147,7 +147,9 @@ func cmdNew(db *sql.DB, opts Options) bool { break } lines = append(lines, string(line)) - log.Printf("%s\n", prettyAttr("eton", string(line))) + if opts.Verbose { + log.Printf("%s\n", prettyAttr("eton", string(line))) + } } value_text = strings.Join(lines, "\n") } else if len(opts.Note) > 0 { @@ -160,7 +162,10 @@ func cmdNew(db *sql.DB, opts Options) bool { value_text = readFile(f.Name()) } - saveString(db, value_text) + lastInsertId := saveString(db, value_text) + if lastInsertId > 0 && opts.Verbose { + fmt.Printf("New note ID:%d\n", lastInsertId) + } return true } @@ -276,7 +281,7 @@ func cmdEdit(db *sql.DB, opts Options) bool { totalUpdated += attr.Edit(db) } - if totalUpdated > 0 { + if opts.Verbose { fmt.Println(totalUpdated, "records updated") } diff --git a/main.go b/main.go index 65cd028..1a31161 100644 --- a/main.go +++ b/main.go @@ -19,9 +19,9 @@ var pwd string const dbfilename string = ".etondb" const usage string = `Usage: - eton new [-|] - eton (ls|grep) [...] [--offset OFFSET] [--limit LIMIT] [--removed-only] [--short] [--all] [--exec COMMAND] [--edit] [--list-files] [--after AFTER] - eton edit [...] + eton new [-|] [-v] + eton (ls|grep) [...] [-Rsl] [-o OFFSET] [-L LIMIT] [--after AFTER] + eton edit [...] [-v] eton alias eton unalias eton mark ... @@ -40,6 +40,8 @@ Options: -r, --recursive recursive mode -l, --list-files list items as filenames -s, --short short mode lists rows with aliases only + -v, --verbose talk a lot + -R, --removed-only only list removed notes ` func main() { diff --git a/models.attr.go b/models.attr.go index cf0fbff..08221af 100644 --- a/models.attr.go +++ b/models.attr.go @@ -401,9 +401,7 @@ func (attr Attr) Edit(db *sql.DB) (rowsAffected int64) { openEditor(filepath) value_text := readFile(filepath) - if value_text == attr.GetValue() { - fmt.Printf("Nothing changed for ID:%d\n", attr.GetID()) - } else { + if value_text != attr.GetValue() { update_stmt, err := db.Prepare("UPDATE attributes SET value_text = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?") check(err) @@ -411,7 +409,6 @@ func (attr Attr) Edit(db *sql.DB) (rowsAffected int64) { check(err) rowsAffected, err = result.RowsAffected() check(err) - fmt.Printf("Updated ID:%d\n", attr.GetID()) } return } @@ -672,17 +669,17 @@ func getLastAttrID(db *sql.DB) int64 { return ID } -func saveString(db *sql.DB, value_text string) { +func saveString(db *sql.DB, value_text string) (lastInsertId int64) { new_stmt, err := db.Prepare("INSERT INTO attributes (name, value_text) VALUES ('note', ?)") check(err) result, err := new_stmt.Exec(value_text) check(err) - lastInsertId, err := result.LastInsertId() + lastInsertId, err = result.LastInsertId() check(err) - fmt.Printf("New note ID:%d\n", lastInsertId) + return } func InitializeDatabase(db *sql.DB) bool { diff --git a/options.go b/options.go index c77907c..dae044d 100644 --- a/options.go +++ b/options.go @@ -25,6 +25,7 @@ type Options struct { Recursive bool RemovedOnly bool ShortMode bool + Verbose bool ListFilepaths bool MountPoint string Note string @@ -111,6 +112,7 @@ func OptionsFromArgs(args map[string]interface{}) (opts Options) { opts.RemovedOnly = args["--removed-only"].(bool) opts.ShortMode = args["--short"].(bool) + opts.Verbose = args["--verbose"].(bool) return }