Skip to content

Commit

Permalink
Alter CLI to trigger on explicit subcommand for better compat
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Crane <marcus@utf9k.net>
  • Loading branch information
marcus-crane committed Jun 8, 2024
1 parent b5f171f commit cd5d47f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 15 additions & 7 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func IsInvokedFromTerminal() bool {

func Invoke(isPortable bool, version string) {
app := &cli.App{
Name: "october",
HelpName: "october",
Name: "october cli",
HelpName: "october cli",
Version: version,
Authors: []*cli.Author{
{
Expand All @@ -35,10 +35,6 @@ func Invoke(isPortable bool, version string) {
},
Usage: "sync your kobo highlights to readwise from your terminal",
Commands: []*cli.Command{
{
Name: "launch",
Usage: "skip cli tool and launch desktop ui",
},
{
Name: "sync",
Aliases: []string{"s"},
Expand Down Expand Up @@ -71,7 +67,19 @@ func Invoke(isPortable bool, version string) {
},
}

err := app.Run(os.Args)
// We remove the cli command so that urfave/cli doesn't try to literally parse it
// but the help text of the cli tool still shows the user `october cli` so they don't
// get disoriented and know that we're juggling text under the hood
var args []string

for k, v := range os.Args {
if k == 1 && v == "cli" {
continue
}
args = append(args, v)
}

err := app.Run(args)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func main() {
isPortable := false
isPortable, _ = strconv.ParseBool(portablebuild)

skipCli := version == "DEV" || len(os.Args) == 2 && os.Args[1] == "launch"

if cli.IsInvokedFromTerminal() && !skipCli {
if len(os.Args) >= 2 && os.Args[1] == "cli" {
cli.Invoke(isPortable, version)
return
}
Expand Down

0 comments on commit cd5d47f

Please sign in to comment.