aboutsummaryrefslogtreecommitdiff
path: root/snap
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 /snap
parentfb8aee6c5147b8751a3920f613934d90b79ef4c5 (diff)
downloadzsu-af8f52e2e4c879935656dd93c2fb564c6e2ce515.tar.xz
zsu-af8f52e2e4c879935656dd93c2fb564c6e2ce515.zip
Parse within subcommands
Diffstat (limited to 'snap')
-rw-r--r--snap/parsing.go19
-rw-r--r--snap/parsing_test.go12
2 files changed, 24 insertions, 7 deletions
diff --git a/snap/parsing.go b/snap/parsing.go
index a848c33..e878077 100644
--- a/snap/parsing.go
+++ b/snap/parsing.go
@@ -78,7 +78,7 @@ func ToRelative(snapish string) * Relative {
return ref;
}
- if ref := parseRelativeSyntax(snapish, "-"); ref != nil {
+ if ref := parseRelativeSyntax(snapish, "~"); ref != nil {
ref.offset = -ref.offset;
return ref;
}
@@ -86,4 +86,21 @@ func ToRelative(snapish string) * Relative {
return &Relative{
snapshot: snapish,
};
+}
+
+// FROM, TO
+func ParseDiff(snapdiff string) (fromRel, toRel *Relative) {
+ snapishes := strings.Split(snapdiff, "..")
+
+ if(len(snapishes) > 2) {
+ die.Fatal("Cannot diff more than two snapshots");
+ }
+
+ fromRel = ToRelative(snapishes[0])
+ toRel = &Relative{}
+ if(len(snapishes) == 2) {
+ toRel = ToRelative(snapishes[1])
+ }
+
+ return
} \ No newline at end of file
diff --git a/snap/parsing_test.go b/snap/parsing_test.go
index 1a87723..4aa232e 100644
--- a/snap/parsing_test.go
+++ b/snap/parsing_test.go
@@ -9,16 +9,16 @@ func TestRelativeParsing(t * testing.T) {
offset int
} {
{"snapshot", "snapshot", 0},
- {"testing--", "testing", -2},
+ {"testing~~", "testing", -2},
{"%SNAPSHOT%^+++", "%SNAPSHOT%^", 3},
- {"--prefixed", "--prefixed", 0},
+ {"~~prefixed", "~~prefixed", 0},
{"+++", "", 3},
- {"---", "", -3},
+ {"~~~", "", -3},
{"+5", "", 5},
- {"-3", "", -3},
+ {"~3", "", -3},
{"+", "", 1},
- {"-", "", -1},
- {`"-"`, "-", 0},
+ {"~", "", -1},
+ {`"~"`, "~", 0},
}
for _, c := range cases {