diff --git a/main.go b/main.go index fae1b54..4defd89 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,8 @@ func main() { switch args[2] { case "show", "-s": cli.EntryReaderShortcut(targetLocation, false) - case "shear": // TODO offline.Shear(targetLocation), exit after run + case "shear": + offline.Shear(targetLocation) case "gen": // TODO offline.Gen(targetLocation), exit after run case "copy": cli.HelpCopy() diff --git a/src/offline/add.go b/src/offline/add.go index 610c5f9..eb103a1 100644 --- a/src/offline/add.go +++ b/src/offline/add.go @@ -9,7 +9,6 @@ func AddFolder(targetLocation string) { // create the directory specified by targetLocation err := os.Mkdir(targetLocation, 0700) if err != nil { - // if the directory already exists, print an error message and exit if os.IsExist(err) { fmt.Println(AnsiError + "Directory already exists" + AnsiReset) os.Exit(1) @@ -19,4 +18,5 @@ func AddFolder(targetLocation string) { } } // TODO If in online mode, create the directory on the server + os.Exit(0) } diff --git a/src/offline/shear.go b/src/offline/shear.go new file mode 100644 index 0000000..7ac1ea5 --- /dev/null +++ b/src/offline/shear.go @@ -0,0 +1,17 @@ +package offline + +import ( + "fmt" + "os" +) + +func Shear(targetLocation string) { + // TODO If in online mode, remove from server and add to shear list + TargetIsFile(targetLocation, true, 0) // needed because os.RemoveAll does not return an error if target does not exist + err := os.RemoveAll(targetLocation) + if err != nil { + fmt.Println(AnsiError + "Failed to remove target: " + err.Error() + AnsiReset) + os.Exit(1) + } + os.Exit(0) +}