4 Commits

3 changed files with 43 additions and 7 deletions

View File

@@ -4,8 +4,8 @@ SERVICE_PREFIX = $(DESTDIR)$(PREFIX)/lib/systemd/user
CFG_PREFIX = $(DESTDIR)/etc
all: version.txt
go build $(GOFLAGS)
go build ./cmd/itctl $(GOFLAGS)
go build
go build ./cmd/itctl
clean:
rm -f itctl

View File

@@ -1,6 +1,7 @@
package main
import (
"time"
"context"
"os"
"os/signal"
@@ -23,9 +24,18 @@ func main() {
syscall.SIGINT,
syscall.SIGTERM,
)
// This goroutine ensures that itctl will exit
// at most 200ms after the user sends SIGINT/SIGTERM.
go func() {
<-ctx.Done()
time.Sleep(200*time.Millisecond)
os.Exit(0)
}()
app := cli.App{
Name: "itctl",
HideHelpCommand: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "socket-path",
@@ -35,6 +45,12 @@ func main() {
},
},
Commands: []*cli.Command{
{
Name: "help",
ArgsUsage: "<command>",
Usage: "Display help screen for a command",
Action: helpCmd,
},
{
Name: "filesystem",
Aliases: []string{"fs"},
@@ -229,11 +245,13 @@ func main() {
},
},
Before: func(c *cli.Context) error {
newClient, err := api.New(c.String("socket-path"))
if err != nil {
return err
if !isHelpCmd() {
newClient, err := api.New(c.String("socket-path"))
if err != nil {
return err
}
client = newClient
}
client = newClient
return nil
},
After: func(*cli.Context) error {
@@ -249,3 +267,21 @@ func main() {
log.Fatal().Err(err).Msg("Error while running app")
}
}
func helpCmd(c *cli.Context) error {
cmdArgs := append([]string{os.Args[0]}, c.Args().Slice()...)
cmdArgs = append(cmdArgs, "-h")
return c.App.RunContext(c.Context, cmdArgs)
}
func isHelpCmd() bool {
if len(os.Args) == 1 {
return true
}
for _, arg := range os.Args {
if arg == "-h" || arg == "help" {
return true
}
}
return false
}

View File

@@ -29,7 +29,7 @@ func newProgress(w fyne.Window) progress {
// Create new rectangle to set the size of the popup
sizeRect := canvas.NewRectangle(color.Transparent)
sizeRect.SetMinSize(fyne.NewSize(300, 50))
// Create vbox for label and progress bar
l := container.NewVBox(out.lbl, out.pb)
// Create popup