/
explain.go
95 lines (71 loc) · 2.31 KB
/
explain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package controller
import (
"sort"
"github.com/spf13/cobra"
"github.com/julien040/gut/src/print"
"github.com/julien040/gut/src/prompt"
)
func Explain(cmd *cobra.Command, args []string) {
var arg string
if len(args) == 0 {
// Create a list of all the commands
commands := []string{}
for command := range explainMessage {
commands = append(commands, command)
}
// Sort the list
sort.Strings(commands)
// Ask the user to choose a command
res, err := prompt.InputSelect("Choose a command", commands)
if err != nil {
exitOnKnownError(errorReadInput, err)
}
arg = res
} else {
arg = args[0]
}
print.Message(findExplainMessageFromArg(arg), print.None)
}
func findExplainMessageFromArg(arg string) string {
// Try to find the message in the map
if message, ok := explainMessage[arg]; ok {
return message
}
return "Sorry, I don't this command 😢"
}
var explainMessage = map[string]string{
"branch": "Sorry I don't know how to explain this command yet",
"clone": `To run this command with git, you would do:
$ git clone <url> <directory>
`,
"diff": `To run this command with git, you would do:
$ git diff --staged`,
"explain": "42",
"fix": "Sorry I don't know how to explain this command yet",
"history": `To run this command with git, you would do:
$ git log --oneline`,
"ignore": "There is no git command for this",
"init": `To run this command with git, you would do:
$ git init`,
"merge": `To run this command with git, you would do:
$ git merge <branch>`,
"profile": "There is no git command for this",
"remote": "Sorry I don't know how to explain this command yet",
"revert": `To run this command with git, you would do:
$ git revert <commit>..HEAD`,
"save": `To run this command with git, you would do:
$ git commit -m "<message>"`,
"squash": `To run this command with git, you would do:
$ git reset --soft <commit>
$ git commit --amend -m <message
`,
"status": `To run this command with git, you would do:
$ git status`,
"switch": `To run this command with git, you would do:
$ git checkout <branch>`,
"sync": "Sorry I don't know how to explain this command yet",
"undo": `To run this command with git, you would do:
$ git reset HEAD --hard`,
"whereami": `To run this command with git, you would do:
$ git rev-parse HEAD && git rev-parse --abbrev-ref HEAD`,
}