From cd70733b098444a0cc79bba5fc70acf7a67c0da3 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Mon, 19 Apr 2021 19:30:57 -0300 Subject: [PATCH] Add `quickstarts list` [CLI-90] (#254) * Add `quickstarts list` * Fix test * Fix linter error * Address review feedback --- internal/auth0/quickstart.go | 10 + internal/cli/apps_test.go | 2 +- internal/cli/data/quickstarts.json | 808 ++++++++++++++++------------- internal/cli/quickstarts.go | 64 ++- internal/cli/tenants.go | 2 +- internal/display/apps.go | 10 +- internal/display/quickstarts.go | 66 +++ internal/display/tenants.go | 4 +- 8 files changed, 569 insertions(+), 397 deletions(-) create mode 100644 internal/auth0/quickstart.go create mode 100644 internal/display/quickstarts.go diff --git a/internal/auth0/quickstart.go b/internal/auth0/quickstart.go new file mode 100644 index 000000000..827e98eb2 --- /dev/null +++ b/internal/auth0/quickstart.go @@ -0,0 +1,10 @@ +package auth0 + +type Quickstart struct { + Name string `json:"name"` + Path string `json:"path"` + Samples []string `json:"samples"` + Org string `json:"org"` + Repo string `json:"repo"` + Branch string `json:"branch,omitempty"` +} diff --git a/internal/cli/apps_test.go b/internal/cli/apps_test.go index d38e12bc8..7e3aff17e 100644 --- a/internal/cli/apps_test.go +++ b/internal/cli/apps_test.go @@ -51,7 +51,7 @@ func TestClientsListCmd(t *testing.T) { expectTable(t, stdout.String(), []string{"CLIENT ID", "NAME", "TYPE"}, [][]string{ - {"some-id", "some-name", "generic"}, + {"some-id", "some-name", "Generic"}, }, ) } diff --git a/internal/cli/data/quickstarts.json b/internal/cli/data/quickstarts.json index 9d8d8b107..68dfdc193 100644 --- a/internal/cli/data/quickstarts.json +++ b/internal/cli/data/quickstarts.json @@ -1,364 +1,446 @@ { - "backend": [ - { - "name": "ASP.NET Core Web API", - "samples": [ - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnetcore-webapi-samples" - }, - { - "name": "ASP.NET Core Web API v2.1", - "samples": [ - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnetcore-webapi-samples", - "branch": "netcore2.1" - }, - { - "name": "Django API", - "samples": [ - "01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-django-api" - }, - { - "name": "Go", - "samples": [ - "01-Authorization-RS256" - ], - "org": "auth0-samples", - "repo": "auth0-golang-api-samples" - }, - { - "name": "Spring Security 4 Java API", - "samples": [ - "01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-spring-security-api-sample" - }, - { - "name": "Spring Security 5 Java API", - "samples": [ - "01-Authorization-MVC" - ], - "org": "auth0-samples", - "repo": "auth0-spring-security5-api-sample" - }, - { - "name": "Laravel API", - "samples": [ - "01-Authorization-RS256" - ], - "org": "auth0-samples", - "repo": "auth0-laravel-api-samples" - }, - { - "name": "Node (Express) API", - "samples": [ - "01-Authorization-RS256" - ], - "org": "auth0-samples", - "repo": "auth0-express-api-samples" - }, - { - "name": "PHP API", - "samples": [ - "01-Authorization-RS256" - ], - "org": "auth0-samples", - "repo": "auth0-php-api-samples" - }, - { - "name": "Python API", - "samples": [ - "00-Starter-Seed" - ], - "org": "auth0-samples", - "repo": "auth0-python-api-samples" - }, - { - "name": "Ruby On Rails API", - "samples": [ - "01-Authentication-RS256" - ], - "org": "auth0-samples", - "repo": "auth0-rubyonrails-api-samples" - }, - { - "name": "ASP.NET Web API (OWIN)", - "samples": [ - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnet-owin-webapi-samples" - } - ], - "native": [ - { - "name": "Android", - "samples": [ - "00-Login-Kt" - ], - "org": "auth0-samples", - "repo": "auth0-android-sample" - }, - { - "name": "Android - Facebook Login", - "samples": [ - "00-login-facebook" - ], - "org": "auth0-samples", - "repo": "auth0-android-native-social-sample" - }, - { - "name": "Cordova", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-cordova-samples" - }, - { - "name": "Ionic 4", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-ionic4-samples" - }, - { - "name": "iOS Swift", - "samples": [ - "00-Login", - "03-User-Sessions", - "04-Calling-APIs", - "05-5uthorization", - "07-Linking-Accounts", - "08-Credentials-TouchID" - ], - "org": "auth0-samples", - "repo": "auth0-ios-swift-sample" - }, - { - "name": "iOS Swift - Facebook Login", - "samples": [ - "00-login-facebook" - ], - "org": "auth0-samples", - "repo": "auth0-ios-swift-native-social-samples" - }, - { - "name": "iOS Swift - Sign In With Apple", - "samples": [ - "00-login-siwa" - ], - "org": "auth0-samples", - "repo": "auth0-ios-swift-native-social-samples" - }, - { - "name": "React Native", - "samples": [ - "00-Login" - ], - "org": "auth0-samples", - "repo": "auth0-react-native-sample" - }, - { - "name": "Windows Universal App C#", - "samples": [ - "Quickstart/00-Starter-Seed" - ], - "org": "auth0-samples", - "repo": "auth0-uwp-oidc-samples" - }, - { - "name": "WPF / Winforms", - "samples": [ - "Quickstart/00-Starter-Seed" - ], - "org": "auth0-samples", - "repo": "auth0-WinFormsWPF-oidc-samples" - }, - { - "name": "Xamarin", - "samples": [ - "Quickstart/01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-xamarin-oidc-samples" - } - ], - "spa": [ - { - "name": "Angular", - "samples": [ - "Sample-01" - ], - "org": "auth0-samples", - "repo": "auth0-angular-samples" - }, - { - "name": "React", - "samples": [ - "Sample-01" - ], - "org": "auth0-samples", - "repo": "auth0-react-samples" - }, - { - "name": "JavaScript", - "samples": [ - "01-Login", - "02-Calling-an-API" - ], - "org": "auth0-samples", - "repo": "auth0-javascript-samples" - }, - { - "name": "Vue", - "samples": [ - "01-Login", - "02-Calling-an-API" - ], - "org": "auth0-samples", - "repo": "auth0-vue-samples" - } - ], - "webapp": [ - { - "name": "ASP.NET Core", - "samples": [ - "Quickstart/01-Login", - "Quickstart/01-User-Profile", - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnetcore-mvc-samples" - }, - { - "name": "ASP.NET Core v2.1", - "samples": [ - "Quickstart/01-Login", - "Quickstart/01-User-Profile", - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnetcore-mvc-samples", - "branch": "netcore2.1" - }, - { - "name": "ASP.NET (OWIN)", - "samples": [ - "Quickstart/01-Login", - "Quickstart/01-User-Profile", - "Quickstart/01-Authorization" - ], - "org": "auth0-samples", - "repo": "auth0-aspnet-owin-mvc-samples" - }, - { - "name": "Django", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-django-web-app" - }, - { - "name": "Express", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-express-webapp-sample" - }, - { - "name": "Go", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-golang-web-app" - }, - { - "name": "Java", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-servlet-sample" - }, - { - "name": "Java EE", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-java-ee-sample" - }, - { - "name": "Java Spring Boot", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-spring-boot-login-samples" - }, - { - "name": "PHP (Laravel)", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-laravel-php-web-app" - }, - { - "name": "Next.js", - "samples": [ - "Sample-01" - ], - "org": "auth0-samples", - "repo": "auth0-nextjs-samples", - "branch": "main" - }, - { - "name": "Node.js", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-nodejs-webapp-sample" - }, - { - "name": "PHP", - "samples": [ - "00-Starter-Seed" - ], - "org": "auth0-samples", - "repo": "auth0-php-web-app" - }, - { - "name": "Python", - "samples": [ - "01-Login" - ], - "org": "auth0-samples", - "repo": "auth0-python-web-app" - }, - { - "name": "Ruby On Rails", - "samples": [ - "01-Login", - "02-Session-Handling", - "03-User-Profile" - ], - "org": "auth0-samples", - "repo": "auth0-rubyonrails-sample" - } - ] - } + "backend": [ + { + "name": "ASP.NET Core Web API", + "path": "aspnet-core-webapi", + "samples": [ + "Quickstart/01-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnetcore-webapi-samples", + "branch": "master" + }, + { + "name": "ASP.NET Core Web API v2.1", + "path": "aspnet-core-webapi-2", + "samples": [ + "Quickstart/01-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnetcore-webapi-samples", + "branch": "netcore2.1" + }, + { + "name": "ASP.NET Web API (OWIN)", + "path": "webapi-owin", + "samples": [ + "Quickstart/01-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnet-owin-webapi-samples", + "branch": "master" + }, + { + "name": "Django API", + "path": "django", + "samples": [ + "01-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-django-api", + "branch": "master" + }, + { + "name": "Go", + "path": "golang", + "samples": [ + "01-Authorization-RS256" + ], + "org": "auth0-samples", + "repo": "auth0-golang-api-samples", + "branch": "master" + }, + { + "name": "Laravel API", + "path": "laravel", + "samples": [ + "01-Authorization-RS256" + ], + "org": "auth0-samples", + "repo": "auth0-laravel-api-samples", + "branch": "master" + }, + { + "name": "Node (Express) API", + "path": "nodejs", + "samples": [ + "01-Authorization-RS256" + ], + "org": "auth0-samples", + "repo": "auth0-express-api-samples", + "branch": "master" + }, + { + "name": "PHP API", + "path": "php", + "samples": [ + "01-Authenticate-RS256" + ], + "org": "auth0-samples", + "repo": "auth0-php-api-samples", + "branch": "master" + }, + { + "name": "Python API", + "path": "python", + "samples": [ + "00-Starter-Seed" + ], + "org": "auth0-samples", + "repo": "auth0-python-api-samples", + "branch": "master" + }, + { + "name": "Ruby On Rails API", + "path": "rails", + "samples": [ + "01-Authentication-RS256" + ], + "org": "auth0-samples", + "repo": "auth0-rubyonrails-api-samples", + "branch": "master" + }, + { + "name": "Spring Security 4 Java API", + "path": "java-spring-security", + "samples": [ + "01-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-spring-security-api-sample", + "branch": "master" + }, + { + "name": "Spring Security 5 Java API", + "path": "java-spring-security5", + "samples": [ + "01-Authorization-MVC" + ], + "org": "auth0-samples", + "repo": "auth0-spring-security5-api-sample", + "branch": "master" + } + ], + "native": [ + { + "name": "Android", + "path": "android", + "samples": [ + "00-Login-Kt" + ], + "org": "auth0-samples", + "repo": "auth0-android-sample", + "branch": "master" + }, + { + "name": "Android - Facebook Login", + "path": "android-facebook-login", + "samples": [ + "00-login-facebook" + ], + "org": "auth0-samples", + "repo": "auth0-android-native-social-sample", + "branch": "master" + }, + { + "name": "Cordova", + "path": "cordova", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-cordova-samples", + "branch": "master" + }, + { + "name": "Ionic 4", + "path": "ionic4", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-ionic4-samples", + "branch": "master" + }, + { + "name": "iOS Swift", + "path": "ios-swift", + "samples": [ + "00-Login", + "01-Embedded-Login", + "01-Login", + "02-Custom-Login-Form", + "03-User-Sessions", + "04-Calling-APIs", + "05-Authorization", + "07-Linking-Accounts", + "08-Credentials-TouchID" + ], + "org": "auth0-samples", + "repo": "auth0-ios-swift-sample", + "branch": "master" + }, + { + "name": "iOS Swift - Facebook Login", + "path": "ios-swift-facebook-login", + "samples": [ + "00-login-facebook" + ], + "org": "auth0-samples", + "repo": "auth0-ios-swift-native-social-samples", + "branch": "master" + }, + { + "name": "iOS Swift - Sign In With Apple", + "path": "ios-swift-siwa", + "samples": [ + "00-login-siwa" + ], + "org": "auth0-samples", + "repo": "auth0-ios-swift-native-social-samples", + "branch": "master" + }, + { + "name": "React Native", + "path": "react-native", + "samples": [ + "00-Login" + ], + "org": "auth0-samples", + "repo": "auth0-react-native-sample", + "branch": "master" + }, + { + "name": "Windows Universal App C#", + "path": "windows-uwp-csharp", + "samples": [ + "Quickstart/00-Starter-Seed" + ], + "org": "auth0-samples", + "repo": "auth0-uwp-oidc-samples", + "branch": "master" + }, + { + "name": "WPF / Winforms", + "path": "wpf-winforms", + "samples": [ + "Quickstart/00-Starter-Seed" + ], + "org": "auth0-samples", + "repo": "auth0-WinFormsWPF-oidc-samples", + "branch": "master" + }, + { + "name": "Xamarin", + "path": "xamarin", + "samples": [ + "Quickstart/01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-xamarin-oidc-samples", + "branch": "master" + } + ], + "spa": [ + { + "name": "Angular", + "path": "angular", + "samples": [ + "Sample-01" + ], + "org": "auth0-samples", + "repo": "auth0-angular-samples", + "branch": "master" + }, + { + "name": "JavaScript", + "path": "vanillajs", + "samples": [ + "01-Login", + "02-Calling-an-API" + ], + "org": "auth0-samples", + "repo": "auth0-javascript-samples", + "branch": "master" + }, + { + "name": "React", + "path": "react", + "samples": [ + "Sample-01" + ], + "org": "auth0-samples", + "repo": "auth0-react-samples", + "branch": "master" + }, + { + "name": "Vue", + "path": "vuejs", + "samples": [ + "01-Login", + "02-Calling-an-API" + ], + "org": "auth0-samples", + "repo": "auth0-vue-samples", + "branch": "master" + } + ], + "webapp": [ + { + "name": "ASP.NET (OWIN)", + "path": "aspnet-owin", + "samples": [ + "Quickstart/01-Login", + "Quickstart/02-User-Profile", + "Quickstart/03-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnet-owin-mvc-samples", + "branch": "master" + }, + { + "name": "ASP.NET Core", + "path": "aspnet-core", + "samples": [ + "Quickstart/01-Login", + "Quickstart/02-User-Profile", + "Quickstart/03-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnetcore-mvc-samples", + "branch": "master" + }, + { + "name": "ASP.NET Core v2.1", + "path": "aspnet-core-2", + "samples": [ + "Quickstart/01-Login", + "Quickstart/02-User-Profile", + "Quickstart/03-Authorization" + ], + "org": "auth0-samples", + "repo": "auth0-aspnetcore-mvc-samples", + "branch": "netcore2.1" + }, + { + "name": "Django", + "path": "django", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-django-web-app", + "branch": "master" + }, + { + "name": "Express", + "path": "express", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-express-webapp-sample", + "branch": "master" + }, + { + "name": "Go", + "path": "golang", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-golang-web-app", + "branch": "master" + }, + { + "name": "Java", + "path": "java", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-servlet-sample", + "branch": "master" + }, + { + "name": "Java EE", + "path": "java-ee", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-java-ee-sample", + "branch": "master" + }, + { + "name": "Java Spring Boot", + "path": "java-spring-boot", + "samples": [ + "mvc-login" + ], + "org": "auth0-samples", + "repo": "auth0-spring-boot-login-samples", + "branch": "master" + }, + { + "name": "Next.js", + "path": "nextjs", + "samples": [ + "Sample-01" + ], + "org": "auth0-samples", + "repo": "auth0-nextjs-samples", + "branch": "main" + }, + { + "name": "Node.js", + "path": "nodejs", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-nodejs-webapp-sample", + "branch": "master" + }, + { + "name": "PHP", + "path": "php", + "samples": [ + "00-Starter-Seed" + ], + "org": "auth0-samples", + "repo": "auth0-php-web-app", + "branch": "master" + }, + { + "name": "PHP (Laravel)", + "path": "laravel", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-laravel-php-web-app", + "branch": "master" + }, + { + "name": "Python", + "path": "python", + "samples": [ + "01-Login" + ], + "org": "auth0-samples", + "repo": "auth0-python-web-app", + "branch": "master" + }, + { + "name": "Ruby On Rails", + "path": "rails", + "samples": [ + "sample" + ], + "org": "auth0-samples", + "repo": "auth0-rubyonrails-sample", + "branch": "master" + } + ] +} \ No newline at end of file diff --git a/internal/cli/quickstarts.go b/internal/cli/quickstarts.go index 67688225c..3edf52dd0 100644 --- a/internal/cli/quickstarts.go +++ b/internal/cli/quickstarts.go @@ -17,6 +17,7 @@ import ( "strings" "github.com/auth0/auth0-cli/internal/ansi" + "github.com/auth0/auth0-cli/internal/auth0" "github.com/auth0/auth0-cli/internal/prompt" "github.com/mholt/archiver/v3" "github.com/spf13/cobra" @@ -33,10 +34,17 @@ const ( qspDefaultPort = 3000 ) +const ( + quickstartEndpoint = `https://auth0.com/docs/package/v2` + quickstartContentType = `application/json` + quickstartOrg = "auth0-samples" + quickstartDefaultCallbackURL = `https://YOUR_APP/callback` +) + var ( //go:embed data/quickstarts.json qsBuf []byte - quickstartsByType = func() (qs map[string][]quickstart) { + quickstartsByType = func() (qs map[string][]auth0.Quickstart) { if err := json.Unmarshal(qsBuf, &qs); err != nil { panic(err) } @@ -57,14 +65,6 @@ var ( } ) -type quickstart struct { - Name string `json:"name"` - Samples []string `json:"samples"` - Org string `json:"org"` - Repo string `json:"repo"` - Branch string `json:"branch,omitempty"` -} - func quickstartsCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "quickstarts", @@ -74,12 +74,32 @@ func quickstartsCmd(cli *cli) *cobra.Command { } cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(downloadQuickstart(cli)) + cmd.AddCommand(listQuickstartsCmd(cli)) + cmd.AddCommand(downloadQuickstartCmd(cli)) return cmd } -func downloadQuickstart(cli *cli) *cobra.Command { +func listQuickstartsCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"ls"}, + Args: cobra.NoArgs, + Short: "List the available Quickstarts", + Long: "List the available Quickstarts.", + Example: `auth0 quickstarts list +auth0 quickstarts ls +auth0 qs list +auth0 qs ls`, + Run: func(cmd *cobra.Command, args []string) { + cli.renderer.QuickstartList(quickstartsByType) + }, + } + + return cmd +} + +func downloadQuickstartCmd(cli *cli) *cobra.Command { var inputs struct { ClientID string Stack string @@ -88,9 +108,10 @@ func downloadQuickstart(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "download", Args: cobra.MaximumNArgs(1), - Short: "Download a quickstart sample app for a specific tech stack", - Long: "Download a quickstart sample app for a specific tech stack.", - Example: "auth0 quickstarts download --stack ", + Short: "Download a Quickstart sample app for a specific tech stack", + Long: "Download a Quickstart sample app for a specific tech stack.", + Example: `auth0 quickstarts download --stack +auth0 qs download --stack `, PreRun: func(cmd *cobra.Command, args []string) { prepareInteractivity(cmd) }, @@ -188,14 +209,7 @@ func downloadQuickstart(cli *cli) *cobra.Command { return cmd } -const ( - quickstartEndpoint = `https://auth0.com/docs/package/v2` - quickstartContentType = `application/json` - quickstartOrg = "auth0-samples" - quickstartDefaultCallbackURL = `https://YOUR_APP/callback` -) - -func downloadQuickStart(ctx context.Context, cli *cli, client *management.Client, target string, q quickstart) error { +func downloadQuickStart(ctx context.Context, cli *cli, client *management.Client, target string, q auth0.Quickstart) error { var payload struct { Branch string `json:"branch"` Org string `json:"org"` @@ -306,18 +320,18 @@ func quickstartPathFor(client *management.Client) (p string, exists bool, err er return target, exists, nil } -func getQuickstart(t, stack string) (quickstart, error) { +func getQuickstart(t, stack string) (auth0.Quickstart, error) { qsType := quickstartsTypeFor(t) quickstarts, ok := quickstartsByType[qsType] if !ok { - return quickstart{}, fmt.Errorf("Unknown quickstart type: %s", qsType) + return auth0.Quickstart{}, fmt.Errorf("Unknown quickstart type: %s", qsType) } for _, q := range quickstarts { if strings.EqualFold(q.Name, stack) { return q, nil } } - return quickstart{}, fmt.Errorf("Quickstart not found for %s/%s", qsType, stack) + return auth0.Quickstart{}, fmt.Errorf("Quickstart not found for %s/%s", qsType, stack) } func quickstartStacksFromType(t string) ([]string, error) { diff --git a/internal/cli/tenants.go b/internal/cli/tenants.go index 8105b0ee8..7f9a3da93 100644 --- a/internal/cli/tenants.go +++ b/internal/cli/tenants.go @@ -39,7 +39,7 @@ func listTenantCmd(cli *cli) *cobra.Command { tenNames[i] = t.Domain } - cli.renderer.ShowTenants(tenNames) + cli.renderer.TenantList(tenNames) return nil }, } diff --git a/internal/display/apps.go b/internal/display/apps.go index 020012b9c..982ce3edb 100644 --- a/internal/display/apps.go +++ b/internal/display/apps.go @@ -15,10 +15,10 @@ const ( quickstartsRegularWeb = "https://auth0.com/docs/quickstart/webapp" quickstartsM2M = "https://auth0.com/docs/quickstart/backend" quickstartsGeneric = "https://auth0.com/docs/quickstarts" - friendlyM2M = "machine to machine" - friendlyNative = "native" - friendlySpa = "single page application" - friendlyReg = "regular web application" + friendlyM2M = "Machine to Machine" + friendlyNative = "Native" + friendlySpa = "Single Page Web Application" + friendlyReg = "Regular Web Application" ) type applicationView struct { @@ -272,7 +272,7 @@ const deprecatedAppName = "All Applications" func appTypeFor(v *string) string { switch { case v == nil: - return "generic" + return "Generic" case *v == "non_interactive": return friendlyM2M diff --git a/internal/display/quickstarts.go b/internal/display/quickstarts.go new file mode 100644 index 000000000..830e233b6 --- /dev/null +++ b/internal/display/quickstarts.go @@ -0,0 +1,66 @@ +package display + +import ( + "fmt" + "sort" + + "github.com/auth0/auth0-cli/internal/auth0" +) + +const ( + qsBaseURL = "https://auth0.com/docs/quickstart" +) + +type quickstartView struct { + Stack string + AppType string + URL string +} + +func (v *quickstartView) AsTableHeader() []string { + return []string{"Quickstart", "Type", "URL"} +} + +func (v *quickstartView) AsTableRow() []string { + return []string{v.Stack, applyColor(v.AppType), v.URL} +} + +func (r *Renderer) QuickstartList(qs map[string][]auth0.Quickstart) { + r.Heading() + + var results []View + keys := make([]string, 0, len(qs)) + + for key := range qs { + keys = append(keys, key) + } + + sort.Strings(keys) + + for _, key := range keys { + for _, item := range qs[key] { + results = append(results, &quickstartView{ + Stack: item.Name, + AppType: applyColor(qsAppTypeFor(key)), + URL: fmt.Sprintf("%s/%s/%s", qsBaseURL, key, item.Path), + }) + } + } + + r.Results(results) +} + +func qsAppTypeFor(s string) string { + switch s { + case "native": + return friendlyNative + case "spa": + return friendlySpa + case "webapp": + return friendlyReg + case "backend": + return friendlyM2M + default: + return "" + } +} diff --git a/internal/display/tenants.go b/internal/display/tenants.go index 969f4922a..e5d94555c 100644 --- a/internal/display/tenants.go +++ b/internal/display/tenants.go @@ -1,7 +1,7 @@ package display type tenantView struct { - Name string + Name string } func (v *tenantView) AsTableHeader() []string { @@ -12,7 +12,7 @@ func (v *tenantView) AsTableRow() []string { return []string{v.Name} } -func (r *Renderer) ShowTenants(data []string) { +func (r *Renderer) TenantList(data []string) { r.Heading() var results []View