-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.go
125 lines (109 loc) · 3.13 KB
/
command.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"flag"
"fmt"
"os"
"strconv"
"strings"
)
// Command line flags
type CmdFlags struct {
Add string
Edit string
Del int
List bool
Version bool
}
var FlagUsage = struct {
Add string
Del string
Edit string
List string
Version string
}{
Add: `
Add a new Apps Script file location:
- [how] Between quotation marks add a name or title then
a colon (:) and the file id. Close quotation marks.
- [syntax] claspall -add "title:Apps-Script-File-Id"
- [example]
claspall -add "Prod:1_hg5Lj-lOXbZMm60FizXSEZBmYN27-ozK-JOX4fRmEWntroxQ"
- [more]
-- You might consider having a "Test" project and a "Production" project AppsScirpt file
-- You can find the project ID in the 'Project Settings' > 'IDs' section.
-- Don't include the current project you are working in. This will be your 'Dev' file.
`,
Del: `
Delete an Apps Script file location:
- [how] Select an Apps Script file reference to delete by number from the -list.
- [syntax] claspall -del Number
- [example]
claspall -del 1
- [more]
-- You can use the -list flag to get the selected file location to remove
-- This will not delete the file. It will stop the deleted file from being updated from the core file.
`,
Edit: `
Edit existing Apps Script file location information:
- [how] Select an Apps Script file reference from the list and update the title and/or file id.
- [syntax] claspall -edit id:title:Apps-Script-File-Id
- [example]
claspall -edit "1:Prod:1_hg5Lj-lOXbZMm60FizXSEZBmYN27-ozK-JOX4fRmEWntroxQ
- [more]
-- to edit just the Title: "1:New Title:"
--- Leave out the id after the first colon.
-- To edit just the Apps Script File ID:
"1::1_hg5Lj-lOXbZMm60FizXSEZBmYN27-ozK-JOX4fRmEWntroxQ"
--- Leave out the name between the ID and the Apps Script File ID colon separators.
`,
List: `
Lists all connected file locations
`,
Version: version,
}
func NewCmdFlags() *CmdFlags {
cf := CmdFlags{}
flag.StringVar(&cf.Add, "add", "", FlagUsage.Add)
flag.IntVar(&cf.Del, "del", -1, FlagUsage.Del)
flag.StringVar(&cf.Edit, "edit", "", FlagUsage.Edit)
flag.BoolVar(&cf.List, "list", false, FlagUsage.List)
flag.BoolVar(&cf.List, "ls", false, "See -list")
flag.BoolVar(&cf.Version, "version", false, FlagUsage.Version)
flag.BoolVar(&cf.Version, "v", false, "See -version")
flag.Parse()
return &cf
}
func (cf CmdFlags) Execute(files *Files) {
switch {
case flag.NFlag() == 0:
ClaspPush(files)
case cf.List:
files.list()
case cf.Add != "":
parts := strings.SplitN(cf.Add, ":", 2)
if len(parts) != 2 {
fmt.Println("💥 Error, invalid format for Add.")
fmt.Print(FlagUsage.Add)
os.Exit(1)
}
files.add(parts[0], parts[1])
case cf.Edit != "":
parts := strings.SplitN(cf.Edit, ":", 3)
if len(parts) != 3 {
fmt.Println("💥 Error, invalid format for Edit.")
fmt.Print(FlagUsage.Edit)
os.Exit(1)
}
line, err := strconv.Atoi(parts[0])
if err != nil {
fmt.Println("💥 Error, invalid line number to edit")
fmt.Print(FlagUsage.Edit)
os.Exit(1)
}
files.edit(line, parts[1], parts[2])
case cf.Del != -1:
files.delete(cf.Del)
case cf.Version:
fmt.Println(version)
}
}