From c71ad9cc79031a3bff70ddfcef6d06761fbc2163 Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Sun, 16 May 2021 16:59:49 +0800 Subject: [PATCH] Close #10 Drag to Decrypt --- cmd/um/main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index d8219b9..830f051 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -12,7 +12,6 @@ import ( "github.com/unlock-music/cli/internal/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" - "log" "os" "path/filepath" "strings" @@ -27,9 +26,10 @@ func main() { Usage: "Unlock your encrypted music file https://github.com/unlock-music/cli", Version: AppVersion, Flags: []cli.Flag{ - &cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: true}, - &cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: true}, + &cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: false}, + &cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: false}, }, + Action: appMain, Copyright: "Copyright (c) 2020 Unlock Music https://github.com/unlock-music/cli/blob/master/LICENSE", HideHelpCommand: true, @@ -37,13 +37,25 @@ func main() { } err := app.Run(os.Args) if err != nil { - log.Fatal(err) + logging.Log().Fatal("run app failed", zap.Error(err)) } } func appMain(c *cli.Context) error { input := c.String("input") + if input == "" && c.Args().Present() { + input = c.Args().Get(c.Args().Len() - 1) + } + output := c.String("output") + if output == "" { + var err error + output, err = os.Getwd() + if err != nil { + return err + } + } + inputStat, err := os.Stat(input) if err != nil { return err