-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
183 lines (174 loc) · 4.54 KB
/
main.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package main
import (
"fmt"
"os"
"github.com/srevinsaju/zap/logging"
"github.com/srevinsaju/zap/tui"
"github.com/urfave/cli/v2"
)
var logger = logging.GetLogger()
// https://polyverse.com/blog/how-to-embed-versioning-information-in-go-applications-f76e2579b572/
var (
BuildVersion string = "(local dev build)"
BuildTime string = ""
BuildSource string = ""
)
const DefaultUpdateUrlPrefix string = "https://github.com/srevinsaju/zap/releases/download/continuous"
func getVersion() string {
return fmt.Sprintf("Build:%s %s", BuildVersion, BuildTime)
}
func main() {
// initialize the command line interface
app := &cli.App{
Name: "Zap",
Usage: "⚡️ A command line interface to install AppImages",
Version: getVersion(),
Authors: []*cli.Author{
{
Name: "Srevin Saju",
Email: "[email protected]",
},
{
Name: "Other open source contributors",
},
},
Copyright: "MIT License 2020-2021",
}
app.EnableBashCompletion = true
cli.AppHelpTemplate = tui.AppHelpTemplate()
app.Commands = []*cli.Command{
{
Name: "install",
Usage: "Installs an AppImage",
Aliases: []string{"i"},
Action: installAppImageCliContextWrapper,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "executable",
Usage: "Name of the executable",
},
&cli.StringFlag{
Name: "from",
Usage: "Provide a repository slug, or a direct URL to an appimage.",
},
&cli.BoolFlag{
Name: "github",
Usage: "Use --from as repository slug to fetch from GitHub",
},
&cli.BoolFlag{
Name: "select-first",
Usage: "Disable all prompts, and select the first item from the prompt if there are more than one choice.",
},
&cli.BoolFlag{
Name: "update",
Aliases: []string{"u"},
Usage: "Update installed apps while updating metadata.",
},
&cli.BoolFlag{
Name: "silent",
Aliases: []string{"q", "no-interactive"},
Usage: "Do not ask interactive questions, and produce less logging",
},
&cli.BoolFlag{
Name: "no-filter",
Usage: "Show all appimages regardless of architecture",
},
},
},
{
Name: "update",
Usage: "Update, downgrade or change a version of an AppImage",
Action: updateAppImageCliContextWrapper,
Aliases: []string{"u", "downgrade", "switch"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "executable",
Usage: "Name of the executable which would be used as the unique identifier " +
"of the appimage on your system",
},
&cli.BoolFlag{
Name: "select-first",
Usage: "Disable all prompts, and select the first item from the prompt if there are more than one choice.",
},
&cli.BoolFlag{
Name: "with-au",
Aliases: []string{"with-appimageupdate", "appimageupdate", "au"},
Usage: "Use AppImageUpdate to delta update your appimage using zsync.",
},
&cli.BoolFlag{
Name: "force-remove",
Usage: "Force a remove of a package before updating it",
},
&cli.BoolFlag{
Name: "silent",
Aliases: []string{"q", "no-interactive"},
Usage: "Do not ask interactive questions, and produce less logging",
},
&cli.BoolFlag{
Name: "no-filter",
Usage: "Show all appimages regardless of architecture",
},
},
},
{
Name: "self-update",
Usage: "Check for updates and update zap",
Action: selfUpdateCliContextWrapper,
Hidden: BuildSource != "github",
},
{
Name: "search",
Usage: "Search the zap index",
Action: searchAppImagesCliContextWrapper,
},
{
Name: "upgrade",
Usage: "Updates all AppImages",
Action: upgradeAppImageCliContextWrapper,
},
{
Name: "remove",
Usage: "Removes an AppImage",
Action: removeAppImageCliContextWrapper,
},
{
Name: "list",
Usage: "List the installed AppImages",
Action: listAppImageCliContextWrapper,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-color",
Usage: "Do not show AppImage executable names in color",
},
&cli.BoolFlag{
Name: "index",
},
},
},
{
Name: "init",
Usage: "Configure zap interactively",
Action: configCliContextWrapper,
},
{
Name: "daemon",
Usage: "Runs a daemon which periodically checks for updates for installed appimages",
Action: daemonCliContextWrapper,
Aliases: []string{"d"},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "install",
},
},
},
}
// initialize the app
err := app.Run(os.Args)
if err != nil {
if err.Error() == "interrupt" {
fmt.Println("Aborted!")
os.Exit(130)
}
logger.Fatal(err)
}
}