-
Notifications
You must be signed in to change notification settings - Fork 55
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
refactor: quickstarts flags #169
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c035c06
refactor: quickstarts flags
jfatta 8cd8d35
Update internal/cli/quickstarts.go
jfatta 3e7afb9
Update internal/cli/quickstarts.go
jfatta ce9704e
Update internal/cli/quickstarts.go
jfatta 6b90c42
refactor: rename flags
jfatta 24811b8
fix: quickstart stack is mandatory
jfatta 8985c8d
Merge branch 'main' into refactor-qs-flags
jfatta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,15 @@ import ( | |
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
// QuickStart app types and defaults | ||
const ( | ||
qsNative = "native" | ||
qsSpa = "spa" | ||
qsWebApp = "webapp" | ||
qsBackend = "backend" | ||
_defaultURL = "http://localhost:3000" | ||
) | ||
|
||
var ( | ||
//go:embed data/quickstarts.json | ||
qsBuf []byte | ||
|
@@ -31,15 +40,21 @@ var ( | |
} | ||
return | ||
}() | ||
) | ||
|
||
// QuickStart app types and defaults | ||
const ( | ||
qsNative = "native" | ||
qsSpa = "spa" | ||
qsWebApp = "webapp" | ||
qsBackend = "backend" | ||
_defaultURL = "http://localhost:3000" | ||
clientID = Flag{ | ||
Name: "ClientID", | ||
jfatta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LongForm: "client ID", | ||
jfatta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ShortForm: "c", | ||
Help: "Client Id of an Auth0 application.", | ||
IsRequired: true, | ||
} | ||
|
||
stack = Flag{ | ||
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. Idem above ( |
||
Name: "Stack", | ||
LongForm: "stack", | ||
ShortForm: "s", | ||
Help: "Tech/Language of the quickstart sample to download", | ||
jfatta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
) | ||
|
||
type quickstart struct { | ||
|
@@ -64,16 +79,15 @@ func quickstartsCmd(cli *cli) *cobra.Command { | |
} | ||
|
||
func downloadQuickstart(cli *cli) *cobra.Command { | ||
var flags struct { | ||
var inputs struct { | ||
ClientID string | ||
Type string | ||
Stack string | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "download", | ||
Short: "Download a quickstart sample app for a specific tech stack", | ||
Long: `auth0 quickstarts download --type <type> --client-id <client-id> --stack <stack>`, | ||
Long: `auth0 quickstarts download --client-id <client-id> --stack <stack>`, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
prepareInteractivity(cmd) | ||
}, | ||
|
@@ -82,30 +96,24 @@ func downloadQuickstart(cli *cli) *cobra.Command { | |
return errors.New("This command can only be run on interactive mode") | ||
} | ||
|
||
selectedClientID := flags.ClientID | ||
|
||
if selectedClientID == "" { | ||
input := prompt.TextInput("client-id", "Client Id:", "Client Id of an Auth0 application.", true) | ||
if err := prompt.AskOne(input, &selectedClientID); err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %v", err) | ||
} | ||
if err := clientID.Ask(cmd, &inputs.ClientID); err != nil { | ||
return err | ||
} | ||
|
||
client, err := cli.api.Client.Read(selectedClientID) | ||
client, err := cli.api.Client.Read(inputs.ClientID) | ||
if err != nil { | ||
return fmt.Errorf("An unexpected error occurred, please verify your client id: %v", err.Error()) | ||
} | ||
|
||
selectedStack := flags.Stack | ||
|
||
if selectedStack == "" { | ||
if inputs.Stack == "" { | ||
// get the valid types for this App: | ||
stacks, err := quickstartStacksFromType(client.GetAppType()) | ||
if err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %v", err) | ||
} | ||
input := prompt.SelectInput("stack", "Stack:", "Tech/Language of the quickstart sample to download", stacks, true) | ||
if err := prompt.AskOne(input, &selectedStack); err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %v", err) | ||
// ask for input using the valid types only: | ||
if err := stack.Select(cmd, &inputs.Stack, stacks); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
|
@@ -120,13 +128,13 @@ func downloadQuickstart(cli *cli) *cobra.Command { | |
} | ||
} | ||
|
||
q, err := getQuickstart(client.GetAppType(), selectedStack) | ||
q, err := getQuickstart(client.GetAppType(), inputs.Stack) | ||
if err != nil { | ||
return fmt.Errorf("An unexpected error occurred with the specified stack %v: %v", selectedStack, err) | ||
return fmt.Errorf("An unexpected error occurred with the specified stack %v: %v", inputs.Stack, err) | ||
} | ||
|
||
err = ansi.Spinner("Downloading quickstart sample", func() error { | ||
return downloadQuickStart(context.TODO(), cli, client, target, q) | ||
return downloadQuickStart(cmd.Context(), cli, client, target, q) | ||
}) | ||
|
||
if err != nil { | ||
|
@@ -144,10 +152,9 @@ func downloadQuickstart(cli *cli) *cobra.Command { | |
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.Flags().StringVarP(&flags.ClientID, "client-id", "c", "", "Client Id of an Auth0 application.") | ||
cmd.Flags().StringVarP(&flags.Stack, "stack", "s", "", "Tech/Language of the quickstart sample to download.") | ||
mustRequireFlags(cmd, "client-id") | ||
|
||
clientID.RegisterString(cmd, &inputs.ClientID, "") | ||
stack.RegisterString(cmd, &inputs.Stack, "") | ||
return cmd | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you please prefix it with
qs
(qsClientID
), until we move it to its own package?