Skip to content

Commit

Permalink
Added import feature & updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
int3rlop3r committed Sep 1, 2020
1 parent 189c151 commit cc5bf2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Jot stuff down without messing up your workspace!
-l List jot files in the working directory
-o Print file contents on the standard output
-d Delete a jot from the working directory
-m Import a file. The resulting file's name will be the jot's name
-clean-all Remove all jot files in the system (dangerous)
-list-tracked List all tracked dirs
-help Print Help (this message) and exit


### Install

$ go get github.com/int3rlop3r/jot
Expand Down
30 changes: 29 additions & 1 deletion jot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ var (
l = flag.Bool("l", false, "List jot files in the working directory")
o = flag.String("o", "", "Print file contents on the standard output")
d = flag.String("d", "", "Delete a jot from the working directory")
m = flag.String("m", "", "Import a file. The resulting file's name will be the jot's name")
cleanAll = flag.Bool("clean-all", false, "Remove all jot files in the system (dangerous)")
listTracked = flag.Bool("list-tracked", false, "List all tracked dirs")
help = flag.Bool("help", false, "Print Help (this message) and exit")
)

func showUsage() {
var args = []string{"t", "u", "l", "o", "d", "clean-all", "list-tracked", "help"}
var args = []string{"t", "u", "l", "o", "d", "m", "clean-all", "list-tracked", "help"}
fmt.Fprintf(os.Stderr, `Jot - jot stuff down without messing up your workspace!
usage: jot [file] edit jot file in working directory
Expand Down Expand Up @@ -120,6 +121,33 @@ func processArgs() {
return
}
fmt.Println("deleted:", *d)
case *m != "":

// first check if the dir is tracked
id, err := db.getJotDir(curDir)
if err != nil {
fmt.Fprint(os.Stderr, "DB err:", err)
return
}

// next read text file contents
_, jotName := filepath.Split(*m)
jotContents, err := ioutil.ReadFile(*m)
if err != nil {
fmt.Fprint(os.Stderr, "Import err:", err)
return
}

// construct and save the jot
newJot := true
jotConts := string(jotContents)
jot := &Jot{id, jotName, &jotConts, time.Now()}
err = db.saveJot(jot, newJot)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
}
fmt.Printf("saved '%s'\n", jotName)
case *listTracked:
res, err := db.listAllDirs()
if err != nil {
Expand Down

0 comments on commit cc5bf2a

Please sign in to comment.