Skip to content

Commit 36bbd99

Browse files
author
abirhalaconstantines
committed
Removing update command, it is, in effect: useless!
1 parent 4da7007 commit 36bbd99

File tree

4 files changed

+21
-61
lines changed

4 files changed

+21
-61
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ sd
22
sd.exe
33
linux*
44
windows*
5+
darwin*

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fi
2727

2828
FILENAME=$OS-$ARCH.$EXT
2929

30-
DOWNLOAD_URL="https://github.com/alexanderConstantinescu/go-speed-dial/releases/download/0.2/$FILENAME"
30+
DOWNLOAD_URL="https://github.com/alexanderConstantinescu/go-speed-dial/releases/download/0.3/$FILENAME"
3131

3232
echo "Downloading speed dial from $DOWNLOAD_URL"
3333

sd.bash-completion

+3-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ _sd() {
5151

5252
GLOBAL_COMMANDS="\
5353
save\
54-
update\
5554
delete\
5655
get\
5756
export\
@@ -66,12 +65,12 @@ _sd() {
6665

6766
GET_OPTIONS="\
6867
-key\
69-
-value"
68+
-val"
7069

7170
DELETE_OPTIONS="\
7271
-key"
7372

74-
SAVE_UPDATE_OPTIONS="\
73+
SAVE_OPTIONS="\
7574
-key\
7675
-val"
7776

@@ -84,11 +83,7 @@ _sd() {
8483

8584
case "${firstword}" in
8685
save)
87-
complete_options="$SAVE_UPDATE_OPTIONS"
88-
;;
89-
update)
90-
complete_words=$( sd get -key )
91-
complete_options="$SAVE_UPDATE_OPTIONS"
86+
complete_options="$SAVE_OPTIONS"
9287
;;
9388
delete)
9489
complete_words=$( sd get -key )

sd.go

+16-52
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var (
3333
get string = "get"
3434
keys string = "keys"
3535
save string = "save"
36-
update string = "update"
3736
del string = "delete"
3837
export string = "export"
3938
list string = "list"
@@ -43,8 +42,7 @@ var (
4342
)
4443

4544
var helpText map[string]string = map[string]string{
46-
save : "save\tSave a command as a speed dial key",
47-
update : "update\tUpdate a saved speed dial key",
45+
save : "save\tSave/update a command as a speed dial key",
4846
del : "delete\tDelete a saved speed dial key",
4947
get : "get\tGet speed dial entities (keys, values) as a whitespace separated list. Useful for the creation of helper functions (bash completion for ex).",
5048
export : "export\tExport your .dial_key file to another remote location",
@@ -113,7 +111,6 @@ func printMainHelp() {
113111
fmt.Println("Speed dial: a CLI intended to help you remember and faster execute commands you typically write, over and over again.")
114112
fmt.Println("\nCommands:\n")
115113
fmt.Println(helpText[save])
116-
fmt.Println(helpText[update])
117114
fmt.Println(helpText[del])
118115
fmt.Println(helpText[get])
119116
fmt.Println(helpText[export])
@@ -295,30 +292,24 @@ func main() {
295292
}
296293

297294
saveCommand := flag.NewFlagSet(save, flag.ExitOnError)
298-
updateCommand := flag.NewFlagSet(update, flag.ExitOnError)
299295
deleteCommand := flag.NewFlagSet(del, flag.ExitOnError)
300296
exportCommand := flag.NewFlagSet(export, flag.ExitOnError)
301297

302298
getCommand := flag.NewFlagSet(get, flag.ExitOnError)
303299
getKeyPtr := getCommand.Bool("key", false, "Get keys as a whitespace separated list")
304-
getValuePtr := getCommand.Bool("value", false, "Get values as whitespace separated list")
300+
getValuePtr := getCommand.Bool("val", false, "Get values as whitespace separated list")
305301

306302
listCommand := flag.NewFlagSet(list, flag.ExitOnError)
307303
listLongPtr := listCommand.Bool("l", false, "List saved commands in a non-truncated format independent of screen size")
308304

309305
saveKeyPtr := saveCommand.String("key", "", "Key to save. (Required)")
310306
saveValPtr := saveCommand.String("val", "", "Val to map key to. (Required)\n\n" +
311307
"Note:\n" +
312-
"The key naming: \"keys\" is reserved and white space characters are not allowed in the key naming. \n" +
308+
"White space characters are not allowed in the key naming. \n" +
313309
"Special characters such as: $ - for variable reference or ' - single quoutes need to be escaped using the \\ character\n\t" +
314-
"Ex: speedial save -key ex -val \"for i in {1,2,3}; do echo $\\i; done\"\n\t" +
315-
"or: speedial save -key ex2 -val \"echo I\\'m home\"\n\n" +
316-
"Save is implemented to save non-existing keys. To update a key use command: update\n")
317-
318-
updateKeyPtr := updateCommand.String("key", "", "Key to update. (Required)")
319-
updateValPtr := updateCommand.String("val", "", "Value to update key with. (Required)\n\n" +
320-
"Note:\n" +
321-
"Update is implemented to update existing keys. To save a new use command: save")
310+
"Ex: sd save -key ex -val \"for i in {1,2,3}; do echo $\\i; done\"\n\t" +
311+
"or: sd save -key ex2 -val \"echo I\\'m home\"\n\t" +
312+
"or: sd save -key ex3 -val \"echo {1} {2}\", which can be expanded as: sd ex3 hello world -> hello world")
322313

323314
deleteKeyPtr := deleteCommand.String("key", "", "Key to delete. (Required)")
324315

@@ -341,11 +332,6 @@ func main() {
341332
if isHelpRequested(saveCommand, os.Args) {
342333
os.Exit(0)
343334
}
344-
case update:
345-
updateCommand.Parse(os.Args[2:])
346-
if isHelpRequested(updateCommand, os.Args) {
347-
os.Exit(0)
348-
}
349335
case del:
350336
deleteCommand.Parse(os.Args[2:])
351337
if isHelpRequested(deleteCommand, os.Args) {
@@ -371,49 +357,27 @@ func main() {
371357
os.Exit(0)
372358
default:
373359
sdMap := readFile(true)
374-
val,_ := verifyKey(sdMap, os.Args[1])
360+
val,exists := verifyKey(sdMap, os.Args[1])
361+
if !exists {
362+
fmt.Printf("Cannot execute command: unknown key %s\n", os.Args[1])
363+
os.Exit(1)
364+
}
375365
val = parseCmd(val)
376366
execCmd(val)
377367
}
378368

379369

380370
if saveCommand.Parsed() {
381371

382-
if *saveKeyPtr == "" || *saveValPtr == "" || *saveKeyPtr == "keys" || strings.Contains(*saveKeyPtr, " ") {
372+
if *saveKeyPtr == "" || *saveValPtr == "" || strings.Contains(*saveKeyPtr, " ") {
383373
saveCommand.PrintDefaults()
384374
os.Exit(1)
385375
}
386376
sdMap := readFile(false)
387-
_, exists := verifyKey(sdMap, *saveKeyPtr)
388-
if !exists {
389-
sdMap[*saveKeyPtr] = *saveValPtr
390-
writeFile(sdMap)
391-
392-
fmt.Printf("Saved key %s as value: %s\n", *saveKeyPtr, *saveValPtr)
393-
os.Exit(0)
394-
}
395-
fmt.Printf("Cannot execute command %s, key: %s exists. Use update instead.\n", save, *saveKeyPtr)
396-
os.Exit(1)
397-
}
398-
399-
if updateCommand.Parsed() {
400-
401-
if *updateKeyPtr == "" || *updateValPtr == "" {
402-
updateCommand.PrintDefaults()
403-
os.Exit(1)
404-
}
405-
406-
sdMap := readFile(true)
407-
_, exists := verifyKey(sdMap, *updateKeyPtr)
408-
if exists {
409-
sdMap[*updateKeyPtr] = *updateValPtr
410-
writeFile(sdMap)
411-
412-
fmt.Printf("Updated key %s as value: %s\n", *updateKeyPtr, *updateValPtr)
413-
os.Exit(0)
414-
}
415-
fmt.Printf("Cannot execute command: %s, unknown key %s\n", update, *updateKeyPtr)
416-
os.Exit(1)
377+
sdMap[*saveKeyPtr] = *saveValPtr
378+
writeFile(sdMap)
379+
fmt.Printf("Saved key %s as value: %s\n", *saveKeyPtr, *saveValPtr)
380+
os.Exit(0)
417381
}
418382

419383
if deleteCommand.Parsed() {

0 commit comments

Comments
 (0)