-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cli): add ios dl command for App Store download link #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/gookit/color" | ||
| "github.com/pkg/browser" | ||
| "github.com/urfave/cli/v2" | ||
| ) | ||
|
|
||
| const appStoreURL = "https://apps.apple.com/us/app/shelltime-xyz/id6757661383" | ||
|
|
||
| var IosCommand *cli.Command = &cli.Command{ | ||
| Name: "ios", | ||
| Usage: "iOS app related commands", | ||
| Subcommands: []*cli.Command{ | ||
| { | ||
| Name: "dl", | ||
| Usage: "open the ShellTime iOS app download page on the App Store", | ||
| Action: commandIosDl, | ||
| OnUsageError: func(cCtx *cli.Context, err error, isSubcommand bool) error { | ||
| color.Red.Println(err.Error()) | ||
| return nil | ||
| }, | ||
| }, | ||
| }, | ||
| OnUsageError: func(cCtx *cli.Context, err error, isSubcommand bool) error { | ||
| color.Red.Println(err.Error()) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func commandIosDl(c *cli.Context) error { | ||
| color.Green.Printf("ShellTime iOS App Store URL:\n%s\n", appStoreURL) | ||
|
|
||
| err := browser.OpenURL(appStoreURL) | ||
| if err != nil { | ||
| fmt.Printf("Could not open browser automatically. Please visit the URL above to download.\n") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better command-line-tool citizenship, error or informational messages should be printed to standard error instead of standard output. This prevents polluting stdout, which might be piped to other commands. You can use fmt.Fprintf(c.App.ErrWriter, "Could not open browser automatically. Please visit the URL above to download.\n") |
||
| } | ||
|
|
||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
OnUsageErrorhandler function is duplicated for the main command and its subcommand. To improve maintainability and adhere to the Don't Repeat Yourself (DRY) principle, you can extract this logic into a shared function.