Skip to content
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

Add empty states [CLI-33] #181

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ func askFlag(cmd *cobra.Command, f *Flag, value interface{}, defaultValue *strin
}

func askManyFlag(cmd *cobra.Command, f *Flag, value interface{}, defaultValue *string, isUpdate bool) error {
var strInput struct {
value string
}
var strInput string

if err := askFlag(cmd, f, &strInput.value, defaultValue, isUpdate); err != nil {
if err := askFlag(cmd, f, &strInput, defaultValue, isUpdate); err != nil {
return err
}

*value.(*[]string) = commaSeparatedStringToSlice(strInput.value)
*value.(*[]string) = commaSeparatedStringToSlice(strInput)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func RunLogin(ctx context.Context, cli *cli, expired bool) error {
if expired {
cli.renderer.Warnf("Please sign in to re-authorize the CLI.")
} else {
cli.renderer.Heading("✪ Welcome to the Auth0 CLI 🎊.")
cli.renderer.Infof("✪ Welcome to the Auth0 CLI 🎊.")
cli.renderer.Infof("To set it up, you will need to sign in to your Auth0 account and authorize the CLI to access the API.")
cli.renderer.Infof("If you don't have an account, please go to https://auth0.com/signup, otherwise continue in the browser.\n\n")
}
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"os"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/buildinfo"
"github.com/auth0/auth0-cli/internal/display"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -95,11 +94,7 @@ func Execute() {
// rootCmd.AddCommand(triggersCmd(cli))

if err := rootCmd.ExecuteContext(context.TODO()); err != nil {
header := []string{"error\n"}
if cli.tenant != "" {
header = append([]string{ansi.Bold(cli.tenant)}, header...)
}
cli.renderer.Heading(header...)
cli.renderer.Heading("error")
cli.renderer.Errorf(err.Error())
os.Exit(1)
}
Expand Down
25 changes: 20 additions & 5 deletions internal/display/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ func (v *apiView) Object() interface{} {
}

func (r *Renderer) ApiList(apis []*management.ResourceServer) {
r.Heading(ansi.Bold(r.Tenant), "APIs\n")
resource := "APIs"

r.Heading(resource)

if len(apis) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 apis create' to add one")
return
}

results := []View{}

Expand All @@ -52,17 +60,17 @@ func (r *Renderer) ApiList(apis []*management.ResourceServer) {
}

func (r *Renderer) ApiShow(api *management.ResourceServer) {
r.Heading(ansi.Bold(r.Tenant), "API\n")
r.Heading("API")
r.Result(makeApiView(api))
}

func (r *Renderer) ApiCreate(api *management.ResourceServer) {
r.Heading(ansi.Bold(r.Tenant), "API created\n")
r.Heading("API created")
r.Result(makeApiView(api))
}

func (r *Renderer) ApiUpdate(api *management.ResourceServer) {
r.Heading(ansi.Bold(r.Tenant), "API updated\n")
r.Heading("API updated")
r.Result(makeApiView(api))
}

Expand Down Expand Up @@ -93,7 +101,14 @@ func (v *scopeView) AsTableRow() []string {
}

func (r *Renderer) ScopesList(api string, scopes []*management.ResourceServerScope) {
r.Heading(ansi.Bold(r.Tenant), fmt.Sprintf("Scopes of %s\n", ansi.Bold(api)))
resource := "scopes"

r.Heading(fmt.Sprintf("%s of %s", resource, ansi.Bold(api)))

if len(scopes) == 0 {
r.EmptyState(resource)
return
}

results := []View{}

Expand Down
21 changes: 15 additions & 6 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ func (v *applicationListView) AsTableRow() []string {
}

func (r *Renderer) ApplicationList(clients []*management.Client) {
r.Heading(ansi.Bold(r.Tenant), "applications\n")
resource := "applications"

r.Heading(resource)

if len(clients) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 apps create' to add one")
return
}

var res []View
for _, c := range clients {
if auth0.StringValue(c.Name) == deprecatedAppName {
Expand All @@ -175,7 +184,7 @@ func (r *Renderer) ApplicationList(clients []*management.Client) {
}

func (r *Renderer) ApplicationShow(client *management.Client, revealSecrets bool) {
r.Heading(ansi.Bold(r.Tenant), "application\n")
r.Heading("application")

v := &applicationView{
revealSecret: revealSecrets,
Expand All @@ -197,7 +206,7 @@ func (r *Renderer) ApplicationShow(client *management.Client, revealSecrets bool
}

func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bool) {
r.Heading(ansi.Bold(r.Tenant), "application created\n")
r.Heading("application created")

v := &applicationView{
revealSecret: revealSecrets,
Expand All @@ -221,14 +230,14 @@ func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bo
r.Infof("Quickstarts: %s", quickstartsURIFor(client.AppType))

// TODO(cyx): possibly guard this with a --no-hint flag.
r.Infof("%s: You might wanna try `auth0 test login --client-id %s`",
ansi.Faint("Hint"),
r.Infof("%s You might want to try 'auth0 test login --client-id %s'",
ansi.Faint("Hint:"),
client.GetClientID(),
)
}

func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bool) {
r.Heading(ansi.Bold(r.Tenant), "application updated\n")
r.Heading("application updated")

v := &applicationView{
revealSecret: revealSecrets,
Expand Down
7 changes: 6 additions & 1 deletion internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ func (r *Renderer) Errorf(format string, a ...interface{}) {
}

func (r *Renderer) Heading(text ...string) {
fmt.Fprintf(r.MessageWriter, "\n%s %s\n", ansi.Faint("==="), strings.Join(text, " "))
heading := fmt.Sprintf("%s %s\n", ansi.Bold(r.Tenant), strings.Join(text, " "))
fmt.Fprintf(r.MessageWriter, "\n%s %s\n", ansi.Faint("==="), heading)
}

func (r *Renderer) EmptyState(resource string) {
fmt.Fprintf(r.MessageWriter, "No %s available.\n", resource)
}

type View interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/display/get_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (r *Renderer) GetToken(c *management.Client, t *authutil.TokenResponse) {
r.Heading(ansi.Bold(auth0.StringValue(c.Name)), "tokens\n")
r.Heading(fmt.Sprintf("tokens for %s", auth0.StringValue(c.Name)))

switch r.Format {
case OutputFormatJSON:
Expand Down
10 changes: 7 additions & 3 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ func (v *logView) typeDesc() (typ, desc string) {
}

func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, api auth0.ActionExecutionAPI, noColor, silent bool) {
r.Heading(ansi.Bold(r.Tenant), "logs\n")
resource := "logs"

if len(logs) < 1 {
r.Infof("No logs found; to generate logs, run a test command like `auth0 test login` or `auth0 test token`")
r.Heading(resource)

if len(logs) == 0 {
r.EmptyState(resource)
r.Infof("To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
return
}

var res []View
Expand Down
25 changes: 17 additions & 8 deletions internal/display/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ func (v *ruleView) Object() interface{} {
}

func (r *Renderer) RulesList(rules []*management.Rule) {
r.Heading(ansi.Bold(r.Tenant), "rules\n")
resource := "rules"

r.Heading(resource)

if len(rules) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 rules create' to add one")
return
}

var res []View

//@TODO Provide sort options via flags
Expand All @@ -63,28 +72,28 @@ func (r *Renderer) RulesList(rules []*management.Rule) {
}

func (r *Renderer) RuleCreate(rule *management.Rule) {
r.Heading(ansi.Bold(r.Tenant), "rule created\n")
r.Heading("rule created")
r.Result(makeRuleView(rule))
r.Newline()

// TODO(cyx): possibly guard this with a --no-hint flag.
r.Infof("%s: To edit this rule, do `auth0 rules update %s`",
ansi.Faint("Hint"),
r.Infof("%s To edit this rule, do 'auth0 rules update %s'",
ansi.Faint("Hint:"),
rule.GetID(),
)

r.Infof("%s: You might wanna try `auth0 test login",
ansi.Faint("Hint"),
r.Infof("%s You might wanna try 'auth0 test login'",
ansi.Faint("Hint:"),
)
}

func (r *Renderer) RuleUpdate(rule *management.Rule) {
r.Heading(ansi.Bold(r.Tenant), "rule updated\n")
r.Heading("rule updated")
r.Result(makeRuleView(rule))
}

func (r *Renderer) RuleShow(rule *management.Rule) {
r.Heading(ansi.Bold(r.Tenant), "rule\n")
r.Heading("rule")
r.Result(makeRuleView(rule))
}

Expand Down
2 changes: 2 additions & 0 deletions internal/display/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func (v *tenantView) AsTableRow() []string {
}

func (r *Renderer) ShowTenants(data []string) {
r.Heading()

var results []View
for _, item := range data {
results = append(results, &tenantView{
Expand Down
2 changes: 1 addition & 1 deletion internal/display/try_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func isNotZero(v interface{}) bool {
}

func (r *Renderer) TryLogin(u *authutil.UserInfo, t *authutil.TokenResponse) {
r.Heading(ansi.Bold(r.Tenant), "/userinfo\n")
r.Heading("/userinfo")

out := &userInfoAndTokens{UserInfo: u, Tokens: t}
b, err := json.MarshalIndent(out, "", " ")
Expand Down