aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2021-07-22 00:41:30 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2021-07-22 00:41:30 -0500
commitaf8f52e2e4c879935656dd93c2fb564c6e2ce515 (patch)
tree81498b5f6d84d69fd6a9d83e413b95e1dce7b6c4 /cmd
parentfb8aee6c5147b8751a3920f613934d90b79ef4c5 (diff)
downloadzsu-af8f52e2e4c879935656dd93c2fb564c6e2ce515.tar.xz
zsu-af8f52e2e4c879935656dd93c2fb564c6e2ce515.zip
Parse within subcommands
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cat.go11
-rw-r--r--cmd/diff.go18
-rw-r--r--cmd/helpers.go16
-rw-r--r--cmd/list.go24
-rw-r--r--cmd/overwrite.go20
5 files changed, 66 insertions, 23 deletions
diff --git a/cmd/cat.go b/cmd/cat.go
index 4f54abc..d5a275d 100644
--- a/cmd/cat.go
+++ b/cmd/cat.go
@@ -6,7 +6,16 @@ import (
)
func Cat(params []string) {
+ if(len(params) == 0) {
+ die.Fatal("Reference file is required")
+ }
+
+ if(len(params) > 3) {
+ die.Fatal("Too many arguments provided")
+ }
+
snapRef := snap.ToRelative(params[0])
+ reference := params[1]
- fmt.Println(snapRef);
+ fmt.Println(snapRef, reference);
} \ No newline at end of file
diff --git a/cmd/diff.go b/cmd/diff.go
index 7caf96b..46327b3 100644
--- a/cmd/diff.go
+++ b/cmd/diff.go
@@ -1,21 +1,23 @@
package cmd
import (
- "flag"
"fmt"
+ "golang.flu0r1ne.net/zfdiff/snap"
)
func Diff(params []string) {
- flags := flag.NewFlagSet("diff", flag.ExitOnError)
- var walk bool
+ if(len(params) == 0) {
+ die.Fatal("Reference file is required")
+ }
- const WALK_HELP = "walk backwards through the diff history"
+ if(len(params) > 2) {
+ die.Fatal("Too many arguments provided")
+ }
- flags.BoolVar(&walk, "walk", false, WALK_HELP);
- flags.BoolVar(&walk, "w", false, WALK_HELP);
+ from, to := snap.ParseDiff(params[0])
- flags.Parse(params);
+ reference := params[1]
- fmt.Printf("Your flag is: %t", walk);
+ fmt.Println(from, to, reference);
}
diff --git a/cmd/helpers.go b/cmd/helpers.go
new file mode 100644
index 0000000..858cdfd
--- /dev/null
+++ b/cmd/helpers.go
@@ -0,0 +1,16 @@
+package cmd
+
+import (
+ "os"
+ "log"
+ "flag"
+)
+
+var die = log.New(os.Stderr, "", 0)
+
+func aliasedBoolVar(f * flag.FlagSet, p * bool, value bool, usage string) func(string) {
+
+ return func(name string) {
+ f.BoolVar(p, name, value, usage)
+ }
+} \ No newline at end of file
diff --git a/cmd/list.go b/cmd/list.go
index d2b9a03..99d5f24 100644
--- a/cmd/list.go
+++ b/cmd/list.go
@@ -1,8 +1,8 @@
package cmd
import (
- "flag"
"fmt"
+ "flag"
)
func List(params []string) {
@@ -10,12 +10,28 @@ func List(params []string) {
var withPaths bool
- const WITH_PATHS_HELP = "print paths to the provided reference within the snapshot"
+ withName := aliasedBoolVar(
+ flags,
+ &withPaths,
+ false,
+ "print paths to the provided reference within the snapshot",
+ )
- flags.BoolVar(&withPaths, "paths", false, WITH_PATHS_HELP);
- flags.BoolVar(&withPaths, "p", false, WITH_PATHS_HELP);
+ withName("paths")
+ withName("p")
flags.Parse(params);
+ if(flags.NArg() == 0) {
+ die.Fatal("Reference file is required")
+ }
+
+ if(flags.NArg() > 1) {
+ die.Fatal("Too many arguments provided")
+ }
+
+ reference := flags.Arg(0)
+
+ fmt.Printf(reference)
fmt.Printf("Your flag is: %t", withPaths);
}
diff --git a/cmd/overwrite.go b/cmd/overwrite.go
index 6f4a00b..324dfb4 100644
--- a/cmd/overwrite.go
+++ b/cmd/overwrite.go
@@ -1,21 +1,21 @@
package cmd
import (
- "flag"
"fmt"
+ "golang.flu0r1ne.net/zfdiff/snap"
)
func Overwrite(params [] string) {
- flags := flag.NewFlagSet("overwrite", flag.ExitOnError);
+ if(len(params) == 0) {
+ die.Fatal("Reference file is required")
+ }
- var withBackup bool
+ if(len(params) > 3) {
+ die.Fatal("Too many arguments provided")
+ }
- const WITH_BACKUP_HELP = "backup the file by creating a snapshot"
+ snapRef := snap.ToRelative(params[0])
+ reference := params[1]
- flags.BoolVar(&withBackup, "backup", false, WITH_BACKUP_HELP);
- flags.BoolVar(&withBackup, "b", false, WITH_BACKUP_HELP);
-
- flags.Parse(params);
-
- fmt.Printf("Your flag is: %t", withBackup);
+ fmt.Print(snapRef, reference)
} \ No newline at end of file