From 00516e9c8d1ff3388e66a1616ec8ca60cd42e997 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Tue, 7 Jan 2025 15:09:00 -0500 Subject: [PATCH 01/38] hide help commands from subcommands --- cli/app.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/app.go b/cli/app.go index d2c7a97e277..bae371b5bed 100644 --- a/cli/app.go +++ b/cli/app.go @@ -809,6 +809,7 @@ var app = &cli.App{ { Name: "profiles", Usage: "work with CLI profiles", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "update", @@ -1360,6 +1361,7 @@ var app = &cli.App{ Name: "train", Usage: "train on data", UsageText: "viam train [other options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "submit", @@ -2493,6 +2495,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "training-script", Usage: "manage training scripts for custom ML training", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "upload", @@ -2581,6 +2584,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "auth-app", Usage: "manage third party auth applications", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "register", From fd7dd4855eef551a025eaeeb910e20ece58138cf Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Tue, 7 Jan 2025 15:30:27 -0500 Subject: [PATCH 02/38] declutter login usagetext --- cli/app.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/app.go b/cli/app.go index bae371b5bed..2eec6ec3437 100644 --- a/cli/app.go +++ b/cli/app.go @@ -422,6 +422,7 @@ var app = &cli.App{ // NOTE(benjirewis): maintain `auth` as an alias for backward compatibility. Aliases: []string{"auth"}, Usage: "login to app.viam.com", + UsageText: "viam login [options] [command] [command options]", HideHelpCommand: true, Flags: []cli.Flag{ &cli.BoolFlag{ @@ -436,6 +437,7 @@ var app = &cli.App{ { Name: "print-access-token", Usage: "print the access token associated with current credentials", + UsageText: createUsageText("login print-access-token", []string{}, false), Action: createCommandWithT[emptyArgs](PrintAccessTokenAction), }, { @@ -461,11 +463,13 @@ var app = &cli.App{ { Name: "logout", Usage: "logout from current session", + UsageText: createUsageText("logout", []string{}, false), Action: createCommandWithT[emptyArgs](LogoutAction), }, { Name: "whoami", Usage: "get currently logged-in user", + UsageText: createUsageText("whoami", []string{}, false), Action: createCommandWithT[emptyArgs](WhoAmIAction), }, { From 6b6e744ef8761db406bcd5ba5799eeffcd13f545 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Tue, 7 Jan 2025 15:41:58 -0500 Subject: [PATCH 03/38] remove duplicate command --- cli/app.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cli/app.go b/cli/app.go index 2eec6ec3437..90f3dd4e72a 100644 --- a/cli/app.go +++ b/cli/app.go @@ -495,12 +495,6 @@ var app = &cli.App{ }, Action: createCommandWithT[enableAuthServiceArgs](EnableAuthServiceAction), }, - }, - }, - { - Name: "auth-service", - Usage: "manage auth-service", - Subcommands: []*cli.Command{ { Name: "oauth-app", Usage: "manage the OAuth applications for an organization", From 0f2aaf454c1a7e96fe91929f8ff9e97c23c18ab8 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Tue, 7 Jan 2025 17:03:08 -0500 Subject: [PATCH 04/38] standardize and fix usage text for organizations subcommand --- cli/app.go | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/cli/app.go b/cli/app.go index 90f3dd4e72a..7610627e43e 100644 --- a/cli/app.go +++ b/cli/app.go @@ -437,7 +437,7 @@ var app = &cli.App{ { Name: "print-access-token", Usage: "print the access token associated with current credentials", - UsageText: createUsageText("login print-access-token", []string{}, false), + UsageText: createUsageText("login print-access-token", nil, false), Action: createCommandWithT[emptyArgs](PrintAccessTokenAction), }, { @@ -463,29 +463,32 @@ var app = &cli.App{ { Name: "logout", Usage: "logout from current session", - UsageText: createUsageText("logout", []string{}, false), + UsageText: createUsageText("logout", nil, false), Action: createCommandWithT[emptyArgs](LogoutAction), }, { Name: "whoami", Usage: "get currently logged-in user", - UsageText: createUsageText("whoami", []string{}, false), + UsageText: createUsageText("whoami", nil, false), Action: createCommandWithT[emptyArgs](WhoAmIAction), }, { Name: "organizations", Aliases: []string{"organization", "org"}, Usage: "work with organizations", + UsageText: "viam organizations [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "auth-service", Usage: "manage auth-service", + UsageText: "viam organizations auth-service [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "enable", Usage: "enable auth-service for OAuth applications", - UsageText: createUsageText("enable", []string{generalFlagOrgID}, true), + UsageText: createUsageText("organizations auth-service enable", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -498,11 +501,13 @@ var app = &cli.App{ { Name: "oauth-app", Usage: "manage the OAuth applications for an organization", + UsageText: "viam organizations auth-service oauth-app [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "delete", Usage: "delete an OAuth application", - UsageText: createUsageText("delete", []string{generalFlagOrgID, oauthAppFlagClientID}, true), + UsageText: createUsageText("organizations auth-service oauth-app delete", []string{generalFlagOrgID, oauthAppFlagClientID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -521,7 +526,7 @@ var app = &cli.App{ { Name: "list", Usage: "list oauth applications for an organization", - UsageText: createUsageText("delete", []string{generalFlagOrgID, oauthAppFlagClientID}, true), + UsageText: createUsageText("organizations auth-service oauth-app list", []string{generalFlagOrgID, oauthAppFlagClientID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -534,6 +539,7 @@ var app = &cli.App{ { Name: "update", Usage: "update an OAuth application", + UsageText: createUsageText("organizations auth-service oauth-app update", []string{generalFlagOrgID, oauthAppFlagClientID}, true), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -598,16 +604,19 @@ var app = &cli.App{ { Name: "list", Usage: "list organizations for the current user", + UsageText: createUsageText("organizations list", nil, false), Action: createCommandWithT[emptyArgs](ListOrganizationsAction), }, { Name: "logo", Usage: "manage the logo for an organization", - UsageText: createUsageText("organizations logo", []string{generalFlagOrgID}, true), + UsageText: "viam organizations logo [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "set", Usage: "set the logo for an organization from a local file", + UsageText: createUsageText("organizations logo set", []string{generalFlagOrgID, organizationFlagLogoPath}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -625,6 +634,7 @@ var app = &cli.App{ { Name: "get", Usage: "get the logo for an organization", + UsageText: createUsageText("organizations logo get", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -639,11 +649,13 @@ var app = &cli.App{ { Name: "support-email", Usage: "manage the support email for an organization", - UsageText: createUsageText("organizations support-email", []string{generalFlagOrgID}, true), + UsageText: "viam organizations support-email [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "set", Usage: "set the support email for an organization", + UsageText: createUsageText("organizations support-email set", []string{generalFlagOrgID, organizationFlagSupportEmail}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -661,6 +673,7 @@ var app = &cli.App{ { Name: "get", Usage: "get the support email for an organization", + UsageText: createUsageText("organizations support-email get", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -675,11 +688,13 @@ var app = &cli.App{ { Name: "billing-service", Usage: "manage the organizations billing service", - UsageText: createUsageText("organizations billing-service", []string{generalFlagOrgID}, false), + UsageText: "organizations billing-service [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "get-config", Usage: "get the billing service config for an organization", + UsageText: createUsageText("organizations billing-service get-config", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -692,6 +707,7 @@ var app = &cli.App{ { Name: "disable", Usage: "disable the billing service for an organization", + UsageText: createUsageText("organizations billing-service disable", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -704,6 +720,7 @@ var app = &cli.App{ { Name: "update", Usage: "update the billing service update for an organization", + UsageText: createUsageText("organizations billing-service update", []string{generalFlagOrgID, organizationBillingAddress}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -721,6 +738,7 @@ var app = &cli.App{ { Name: "enable", Usage: "enable the billing service for an organization", + UsageText: createUsageText("organizations billing-service enable", []string{generalFlagOrgID, organizationBillingAddress}, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -740,11 +758,13 @@ var app = &cli.App{ { Name: "api-key", Usage: "work with an organization's api keys", - UsageText: createUsageText("organizations api-key", []string{generalFlagOrgID}, true), + UsageText: "viam organizations api-key [command options]", + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "create", Usage: "create an api key for your organization", + UsageText: createUsageText("viam organizations api-key create", []string{generalFlagOrgID}, true), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, From c8ce0687f0b3cb127f53a142d221b1d8c5de12e8 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 10:51:11 -0500 Subject: [PATCH 05/38] fix list locations command --- cli/app.go | 11 +++++++++-- cli/client.go | 13 +++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cli/app.go b/cli/app.go index 7610627e43e..3b112ff8587 100644 --- a/cli/app.go +++ b/cli/app.go @@ -786,13 +786,20 @@ var app = &cli.App{ Name: "locations", Aliases: []string{"location"}, Usage: "work with locations", + UsageText: "viam locations [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "list", Usage: "list locations for the current user", - ArgsUsage: "[organization]", - Action: createCommandWithT[emptyArgs](ListLocationsAction), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: generalFlagOrganization, + Aliases: []string{generalFlagAliasOrg, generalFlagOrgID, generalFlagAliasOrgName}, + DefaultText: "first organization alphabetically", + }, + }, + Action: createCommandWithT[listLocationsArgs](ListLocationsAction), }, { Name: "api-key", diff --git a/cli/client.go b/cli/client.go index 39953e3335c..8ae9e82b206 100644 --- a/cli/client.go +++ b/cli/client.go @@ -540,15 +540,16 @@ func (c *viamClient) listOAuthAppsAction(cCtx *cli.Context, orgID string) error return nil } +type listLocationsArgs struct { + Organization string +} + // ListLocationsAction is the corresponding Action for 'locations list'. -func ListLocationsAction(c *cli.Context, args emptyArgs) error { +func ListLocationsAction(c *cli.Context, args listLocationsArgs) error { client, err := newViamClient(c) if err != nil { return err } - // TODO(RSDK-9288) - this is brittle and inconsistent with how most data is passed. - // Move this to being a flag (but make sure existing workflows still work!) - orgStr := c.Args().First() listLocations := func(orgID string) error { locs, err := client.listLocations(orgID) if err != nil { @@ -559,6 +560,10 @@ func ListLocationsAction(c *cli.Context, args emptyArgs) error { } return nil } + orgStr := args.Organization + if orgStr == "" && c.Args().First() != "" { + orgStr = c.Args().First() + } if orgStr == "" { orgs, err := client.listOrganizations() if err != nil { From d023c019659416d7d3b9cbca06b6e1174dca3ef2 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 11:03:03 -0500 Subject: [PATCH 06/38] fix usage text for viam command --- cli/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/app.go b/cli/app.go index 3b112ff8587..9fc66e7ad5c 100644 --- a/cli/app.go +++ b/cli/app.go @@ -381,6 +381,7 @@ func formatAcceptedValues(values ...string) string { var app = &cli.App{ Name: "viam", Usage: "interact with your Viam machines", + UsageText: "viam [global options] [command options]", HideHelpCommand: true, Flags: []cli.Flag{ &cli.StringFlag{ From ef67b88810f0f0d3ef1176ab305a3648534f856d Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 12:06:02 -0500 Subject: [PATCH 07/38] make lint --- cli/app.go | 132 ++++++++++++++++++++++++++--------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/cli/app.go b/cli/app.go index 9fc66e7ad5c..714ac0bd423 100644 --- a/cli/app.go +++ b/cli/app.go @@ -381,7 +381,7 @@ func formatAcceptedValues(values ...string) string { var app = &cli.App{ Name: "viam", Usage: "interact with your Viam machines", - UsageText: "viam [global options] [command options]", + UsageText: "viam [global options] [command options]", HideHelpCommand: true, Flags: []cli.Flag{ &cli.StringFlag{ @@ -423,7 +423,7 @@ var app = &cli.App{ // NOTE(benjirewis): maintain `auth` as an alias for backward compatibility. Aliases: []string{"auth"}, Usage: "login to app.viam.com", - UsageText: "viam login [options] [command] [command options]", + UsageText: "viam login [options] [command] [command options]", HideHelpCommand: true, Flags: []cli.Flag{ &cli.BoolFlag{ @@ -436,10 +436,10 @@ var app = &cli.App{ After: createCommandWithT[emptyArgs](CheckUpdateAction), Subcommands: []*cli.Command{ { - Name: "print-access-token", - Usage: "print the access token associated with current credentials", + Name: "print-access-token", + Usage: "print the access token associated with current credentials", UsageText: createUsageText("login print-access-token", nil, false), - Action: createCommandWithT[emptyArgs](PrintAccessTokenAction), + Action: createCommandWithT[emptyArgs](PrintAccessTokenAction), }, { Name: "api-key", @@ -462,28 +462,28 @@ var app = &cli.App{ }, }, { - Name: "logout", - Usage: "logout from current session", + Name: "logout", + Usage: "logout from current session", UsageText: createUsageText("logout", nil, false), - Action: createCommandWithT[emptyArgs](LogoutAction), + Action: createCommandWithT[emptyArgs](LogoutAction), }, { - Name: "whoami", - Usage: "get currently logged-in user", + Name: "whoami", + Usage: "get currently logged-in user", UsageText: createUsageText("whoami", nil, false), - Action: createCommandWithT[emptyArgs](WhoAmIAction), + Action: createCommandWithT[emptyArgs](WhoAmIAction), }, { Name: "organizations", Aliases: []string{"organization", "org"}, Usage: "work with organizations", - UsageText: "viam organizations [command options]", + UsageText: "viam organizations [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "auth-service", - Usage: "manage auth-service", - UsageText: "viam organizations auth-service [command options]", + Name: "auth-service", + Usage: "manage auth-service", + UsageText: "viam organizations auth-service [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -500,9 +500,9 @@ var app = &cli.App{ Action: createCommandWithT[enableAuthServiceArgs](EnableAuthServiceAction), }, { - Name: "oauth-app", - Usage: "manage the OAuth applications for an organization", - UsageText: "viam organizations auth-service oauth-app [command options]", + Name: "oauth-app", + Usage: "manage the OAuth applications for an organization", + UsageText: "viam organizations auth-service oauth-app [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -538,8 +538,8 @@ var app = &cli.App{ Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction), }, { - Name: "update", - Usage: "update an OAuth application", + Name: "update", + Usage: "update an OAuth application", UsageText: createUsageText("organizations auth-service oauth-app update", []string{generalFlagOrgID, oauthAppFlagClientID}, true), Flags: []cli.Flag{ &cli.StringFlag{ @@ -603,20 +603,20 @@ var app = &cli.App{ }, }, { - Name: "list", - Usage: "list organizations for the current user", + Name: "list", + Usage: "list organizations for the current user", UsageText: createUsageText("organizations list", nil, false), - Action: createCommandWithT[emptyArgs](ListOrganizationsAction), + Action: createCommandWithT[emptyArgs](ListOrganizationsAction), }, { - Name: "logo", - Usage: "manage the logo for an organization", - UsageText: "viam organizations logo [command options]", + Name: "logo", + Usage: "manage the logo for an organization", + UsageText: "viam organizations logo [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "set", - Usage: "set the logo for an organization from a local file", + Name: "set", + Usage: "set the logo for an organization from a local file", UsageText: createUsageText("organizations logo set", []string{generalFlagOrgID, organizationFlagLogoPath}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -633,8 +633,8 @@ var app = &cli.App{ Action: createCommandWithT[organizationsLogoSetArgs](OrganizationLogoSetAction), }, { - Name: "get", - Usage: "get the logo for an organization", + Name: "get", + Usage: "get the logo for an organization", UsageText: createUsageText("organizations logo get", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -648,14 +648,14 @@ var app = &cli.App{ }, }, { - Name: "support-email", - Usage: "manage the support email for an organization", - UsageText: "viam organizations support-email [command options]", + Name: "support-email", + Usage: "manage the support email for an organization", + UsageText: "viam organizations support-email [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "set", - Usage: "set the support email for an organization", + Name: "set", + Usage: "set the support email for an organization", UsageText: createUsageText("organizations support-email set", []string{generalFlagOrgID, organizationFlagSupportEmail}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -672,8 +672,8 @@ var app = &cli.App{ Action: createCommandWithT[organizationsSupportEmailSetArgs](OrganizationsSupportEmailSetAction), }, { - Name: "get", - Usage: "get the support email for an organization", + Name: "get", + Usage: "get the support email for an organization", UsageText: createUsageText("organizations support-email get", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -687,14 +687,14 @@ var app = &cli.App{ }, }, { - Name: "billing-service", - Usage: "manage the organizations billing service", - UsageText: "organizations billing-service [command options]", + Name: "billing-service", + Usage: "manage the organizations billing service", + UsageText: "organizations billing-service [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "get-config", - Usage: "get the billing service config for an organization", + Name: "get-config", + Usage: "get the billing service config for an organization", UsageText: createUsageText("organizations billing-service get-config", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -706,8 +706,8 @@ var app = &cli.App{ Action: createCommandWithT[getBillingConfigArgs](GetBillingConfigAction), }, { - Name: "disable", - Usage: "disable the billing service for an organization", + Name: "disable", + Usage: "disable the billing service for an organization", UsageText: createUsageText("organizations billing-service disable", []string{generalFlagOrgID}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -719,8 +719,8 @@ var app = &cli.App{ Action: createCommandWithT[organizationDisableBillingServiceArgs](OrganizationDisableBillingServiceAction), }, { - Name: "update", - Usage: "update the billing service update for an organization", + Name: "update", + Usage: "update the billing service update for an organization", UsageText: createUsageText("organizations billing-service update", []string{generalFlagOrgID, organizationBillingAddress}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -737,8 +737,8 @@ var app = &cli.App{ Action: createCommandWithT[updateBillingServiceArgs](UpdateBillingServiceAction), }, { - Name: "enable", - Usage: "enable the billing service for an organization", + Name: "enable", + Usage: "enable the billing service for an organization", UsageText: createUsageText("organizations billing-service enable", []string{generalFlagOrgID, organizationBillingAddress}, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -757,14 +757,14 @@ var app = &cli.App{ }, }, { - Name: "api-key", - Usage: "work with an organization's api keys", - UsageText: "viam organizations api-key [command options]", + Name: "api-key", + Usage: "work with an organization's api keys", + UsageText: "viam organizations api-key [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "create", - Usage: "create an api key for your organization", + Name: "create", + Usage: "create an api key for your organization", UsageText: createUsageText("viam organizations api-key create", []string{generalFlagOrgID}, true), Flags: []cli.Flag{ &cli.StringFlag{ @@ -787,12 +787,12 @@ var app = &cli.App{ Name: "locations", Aliases: []string{"location"}, Usage: "work with locations", - UsageText: "viam locations [command options]", + UsageText: "viam locations [command options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "list", - Usage: "list locations for the current user", + Name: "list", + Usage: "list locations for the current user", Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, @@ -800,7 +800,7 @@ var app = &cli.App{ DefaultText: "first organization alphabetically", }, }, - Action: createCommandWithT[listLocationsArgs](ListLocationsAction), + Action: createCommandWithT[listLocationsArgs](ListLocationsAction), }, { Name: "api-key", @@ -833,8 +833,8 @@ var app = &cli.App{ }, }, { - Name: "profiles", - Usage: "work with CLI profiles", + Name: "profiles", + Usage: "work with CLI profiles", HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -1384,9 +1384,9 @@ var app = &cli.App{ }, }, { - Name: "train", - Usage: "train on data", - UsageText: "viam train [other options]", + Name: "train", + Usage: "train on data", + UsageText: "viam train [other options]", HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -2519,8 +2519,8 @@ This won't work unless you have an existing installation of our GitHub app on yo }, }, { - Name: "training-script", - Usage: "manage training scripts for custom ML training", + Name: "training-script", + Usage: "manage training scripts for custom ML training", HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -2608,8 +2608,8 @@ This won't work unless you have an existing installation of our GitHub app on yo }, }, { - Name: "auth-app", - Usage: "manage third party auth applications", + Name: "auth-app", + Usage: "manage third party auth applications", HideHelpCommand: true, Subcommands: []*cli.Command{ { From d500403322919dc09fd7f5a7fc3647755c2ae826 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 12:40:07 -0500 Subject: [PATCH 08/38] allow only unrequired options in usage text --- cli/app.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/app.go b/cli/app.go index 714ac0bd423..9a987588f8b 100644 --- a/cli/app.go +++ b/cli/app.go @@ -360,13 +360,17 @@ func createCommandWithT[T any](f func(*cli.Context, T) error) func(*cli.Context) // createUsageText is a helper for formatting UsageTexts. The created UsageText // contains "viam", the command, requiredFlags, [other options] if otherOptions // is true, and all passed-in arguments in that order. -func createUsageText(command string, requiredFlags []string, otherOptions bool, arguments ...string) string { +func createUsageText(command string, requiredFlags []string, unrequiredOptions bool, arguments ...string) string { formatted := []string{"viam", command} for _, flag := range requiredFlags { formatted = append(formatted, fmt.Sprintf("--%s=<%s>", flag, flag)) } - if otherOptions { - formatted = append(formatted, "[other options]") + if unrequiredOptions { + if requiredFlags == nil { + formatted = append(formatted, "[options]") + } else { + formatted = append(formatted, "[other options]") + } } formatted = append(formatted, arguments...) return strings.Join(formatted, " ") From 9598d543d73c4ea997eae45f7379fd4848df58d4 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 13:05:49 -0500 Subject: [PATCH 09/38] add subcommand support to createusagetext --- cli/app.go | 211 +++++++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 96 deletions(-) diff --git a/cli/app.go b/cli/app.go index 9a987588f8b..6add3f8413d 100644 --- a/cli/app.go +++ b/cli/app.go @@ -358,9 +358,10 @@ func createCommandWithT[T any](f func(*cli.Context, T) error) func(*cli.Context) } // createUsageText is a helper for formatting UsageTexts. The created UsageText -// contains "viam", the command, requiredFlags, [other options] if otherOptions -// is true, and all passed-in arguments in that order. -func createUsageText(command string, requiredFlags []string, unrequiredOptions bool, arguments ...string) string { +// contains "viam", the command, requiredFlags, "[other options]" if unrequiredOptions +// is true, " [command options]" if subcommand is true, and all passed-in +// arguments in that order. +func createUsageText(command string, requiredFlags []string, unrequiredOptions, subcommand bool, arguments ...string) string { formatted := []string{"viam", command} for _, flag := range requiredFlags { formatted = append(formatted, fmt.Sprintf("--%s=<%s>", flag, flag)) @@ -372,6 +373,9 @@ func createUsageText(command string, requiredFlags []string, unrequiredOptions b formatted = append(formatted, "[other options]") } } + if subcommand { + formatted = append(formatted, " [command options]") + } formatted = append(formatted, arguments...) return strings.Join(formatted, " ") } @@ -442,13 +446,13 @@ var app = &cli.App{ { Name: "print-access-token", Usage: "print the access token associated with current credentials", - UsageText: createUsageText("login print-access-token", nil, false), + UsageText: createUsageText("login print-access-token", nil, false, false), Action: createCommandWithT[emptyArgs](PrintAccessTokenAction), }, { Name: "api-key", Usage: "authenticate with an api key", - UsageText: createUsageText("login api-key", []string{loginFlagKeyID, loginFlagKey}, false), + UsageText: createUsageText("login api-key", []string{loginFlagKeyID, loginFlagKey}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: loginFlagKeyID, @@ -468,32 +472,32 @@ var app = &cli.App{ { Name: "logout", Usage: "logout from current session", - UsageText: createUsageText("logout", nil, false), + UsageText: createUsageText("logout", nil, false, false), Action: createCommandWithT[emptyArgs](LogoutAction), }, { Name: "whoami", Usage: "get currently logged-in user", - UsageText: createUsageText("whoami", nil, false), + UsageText: createUsageText("whoami", nil, false, false), Action: createCommandWithT[emptyArgs](WhoAmIAction), }, { Name: "organizations", Aliases: []string{"organization", "org"}, Usage: "work with organizations", - UsageText: "viam organizations [command options]", + UsageText: createUsageText("organizations", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "auth-service", Usage: "manage auth-service", - UsageText: "viam organizations auth-service [command options]", + UsageText: createUsageText("organizations auth-service", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "enable", Usage: "enable auth-service for OAuth applications", - UsageText: createUsageText("organizations auth-service enable", []string{generalFlagOrgID}, false), + UsageText: createUsageText("organizations auth-service enable", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -506,13 +510,15 @@ var app = &cli.App{ { Name: "oauth-app", Usage: "manage the OAuth applications for an organization", - UsageText: "viam organizations auth-service oauth-app [command options]", + UsageText: createUsageText("organizations auth-service oauth-app", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "delete", - Usage: "delete an OAuth application", - UsageText: createUsageText("organizations auth-service oauth-app delete", []string{generalFlagOrgID, oauthAppFlagClientID}, false), + Name: "delete", + Usage: "delete an OAuth application", + UsageText: createUsageText( + "organizations auth-service oauth-app delete", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -529,9 +535,11 @@ var app = &cli.App{ Action: createCommandWithT[deleteOAuthAppArgs](DeleteOAuthAppAction), }, { - Name: "list", - Usage: "list oauth applications for an organization", - UsageText: createUsageText("organizations auth-service oauth-app list", []string{generalFlagOrgID, oauthAppFlagClientID}, false), + Name: "list", + Usage: "list oauth applications for an organization", + UsageText: createUsageText( + "organizations auth-service oauth-app list", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -542,9 +550,11 @@ var app = &cli.App{ Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction), }, { - Name: "update", - Usage: "update an OAuth application", - UsageText: createUsageText("organizations auth-service oauth-app update", []string{generalFlagOrgID, oauthAppFlagClientID}, true), + Name: "update", + Usage: "update an OAuth application", + UsageText: createUsageText( + "organizations auth-service oauth-app update", []string{generalFlagOrgID, oauthAppFlagClientID}, true, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -609,19 +619,19 @@ var app = &cli.App{ { Name: "list", Usage: "list organizations for the current user", - UsageText: createUsageText("organizations list", nil, false), + UsageText: createUsageText("organizations list", nil, false, false), Action: createCommandWithT[emptyArgs](ListOrganizationsAction), }, { Name: "logo", Usage: "manage the logo for an organization", - UsageText: "viam organizations logo [command options]", + UsageText: createUsageText("organizations logo", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "set", Usage: "set the logo for an organization from a local file", - UsageText: createUsageText("organizations logo set", []string{generalFlagOrgID, organizationFlagLogoPath}, false), + UsageText: createUsageText("organizations logo set", []string{generalFlagOrgID, organizationFlagLogoPath}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -639,7 +649,7 @@ var app = &cli.App{ { Name: "get", Usage: "get the logo for an organization", - UsageText: createUsageText("organizations logo get", []string{generalFlagOrgID}, false), + UsageText: createUsageText("organizations logo get", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -654,13 +664,15 @@ var app = &cli.App{ { Name: "support-email", Usage: "manage the support email for an organization", - UsageText: "viam organizations support-email [command options]", + UsageText: createUsageText("organizations support-email", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "set", - Usage: "set the support email for an organization", - UsageText: createUsageText("organizations support-email set", []string{generalFlagOrgID, organizationFlagSupportEmail}, false), + Name: "set", + Usage: "set the support email for an organization", + UsageText: createUsageText( + "organizations support-email set", []string{generalFlagOrgID, organizationFlagSupportEmail}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -678,7 +690,7 @@ var app = &cli.App{ { Name: "get", Usage: "get the support email for an organization", - UsageText: createUsageText("organizations support-email get", []string{generalFlagOrgID}, false), + UsageText: createUsageText("organizations support-email get", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -693,13 +705,13 @@ var app = &cli.App{ { Name: "billing-service", Usage: "manage the organizations billing service", - UsageText: "organizations billing-service [command options]", + UsageText: createUsageText("organizations billing-service", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "get-config", Usage: "get the billing service config for an organization", - UsageText: createUsageText("organizations billing-service get-config", []string{generalFlagOrgID}, false), + UsageText: createUsageText("organizations billing-service get-config", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -712,7 +724,7 @@ var app = &cli.App{ { Name: "disable", Usage: "disable the billing service for an organization", - UsageText: createUsageText("organizations billing-service disable", []string{generalFlagOrgID}, false), + UsageText: createUsageText("organizations billing-service disable", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -723,9 +735,11 @@ var app = &cli.App{ Action: createCommandWithT[organizationDisableBillingServiceArgs](OrganizationDisableBillingServiceAction), }, { - Name: "update", - Usage: "update the billing service update for an organization", - UsageText: createUsageText("organizations billing-service update", []string{generalFlagOrgID, organizationBillingAddress}, false), + Name: "update", + Usage: "update the billing service update for an organization", + UsageText: createUsageText( + "organizations billing-service update", []string{generalFlagOrgID, organizationBillingAddress}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -741,9 +755,11 @@ var app = &cli.App{ Action: createCommandWithT[updateBillingServiceArgs](UpdateBillingServiceAction), }, { - Name: "enable", - Usage: "enable the billing service for an organization", - UsageText: createUsageText("organizations billing-service enable", []string{generalFlagOrgID, organizationBillingAddress}, false), + Name: "enable", + Usage: "enable the billing service for an organization", + UsageText: createUsageText( + "organizations billing-service enable", []string{generalFlagOrgID, organizationBillingAddress}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -763,13 +779,13 @@ var app = &cli.App{ { Name: "api-key", Usage: "work with an organization's api keys", - UsageText: "viam organizations api-key [command options]", + UsageText: createUsageText("organizations api-key", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "create", Usage: "create an api key for your organization", - UsageText: createUsageText("viam organizations api-key create", []string{generalFlagOrgID}, true), + UsageText: createUsageText("organizations api-key create", []string{generalFlagOrgID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -778,7 +794,8 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: generalFlagName, - Usage: "the name of the key (defaults to your login info with the current time)", + Usage: "the name of the key", + DefaultText: "login info with current time", }, }, Action: createCommandWithT[organizationsAPIKeyCreateArgs](OrganizationsAPIKeyCreateAction), @@ -813,7 +830,7 @@ var app = &cli.App{ { Name: "create", Usage: "create an api key for your location", - UsageText: createUsageText("api-key create", []string{generalFlagOrgID}, true), + UsageText: createUsageText("api-key create", []string{generalFlagOrgID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagLocationID, @@ -916,7 +933,7 @@ var app = &cli.App{ { Name: "binary", Usage: "download binary data", - UsageText: createUsageText("data export binary", []string{dataFlagDestination}, true), + UsageText: createUsageText("data export binary", []string{dataFlagDestination}, true, false), Flags: append([]cli.Flag{ &cli.PathFlag{ Name: dataFlagDestination, @@ -949,7 +966,7 @@ var app = &cli.App{ dataFlagResourceName, dataFlagResourceSubtype, dataFlagMethod, - }, true), + }, true, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: dataFlagDestination, @@ -997,7 +1014,7 @@ var app = &cli.App{ { Name: "binary", Usage: "delete binary data from Viam cloud", - UsageText: createUsageText("data delete binary", nil, true), + UsageText: createUsageText("data delete binary", nil, true, false), Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: dataFlagOrgIDs, @@ -1067,7 +1084,7 @@ var app = &cli.App{ { Name: "tabular", Usage: "delete tabular data from Viam cloud", - UsageText: createUsageText("data delete tabular", []string{generalFlagOrgID, dataFlagDeleteTabularDataOlderThanDays}, false), + UsageText: createUsageText("data delete tabular", []string{generalFlagOrgID, dataFlagDeleteTabularDataOlderThanDays}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -1087,12 +1104,12 @@ var app = &cli.App{ { Name: "database", Usage: "interact with a MongoDB Atlas Data Federation instance", - UsageText: createUsageText("data database", nil, true), + UsageText: createUsageText("data database", nil, true, false), Subcommands: []*cli.Command{ { Name: "configure", Usage: "configures a database user for the Viam org's MongoDB Atlas Data Federation instance", - UsageText: createUsageText("data database configure", []string{generalFlagOrgID, dataFlagDatabasePassword}, false), + UsageText: createUsageText("data database configure", []string{generalFlagOrgID, dataFlagDatabasePassword}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -1111,7 +1128,7 @@ var app = &cli.App{ { Name: "hostname", Usage: "gets the hostname to access a MongoDB Atlas Data Federation Instance", - UsageText: createUsageText("data database hostname", []string{generalFlagOrgID}, false), + UsageText: createUsageText("data database hostname", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -1126,12 +1143,12 @@ var app = &cli.App{ { Name: "tag", Usage: "tag binary data by filter or ids", - UsageText: createUsageText("data tag", nil, true), + UsageText: createUsageText("data tag", nil, true, false), Subcommands: []*cli.Command{ { Name: "ids", Usage: "adds or removes tags from binary data by file ids for a given org and location", - UsageText: createUsageText("data tag ids", nil, true), + UsageText: createUsageText("data tag ids", nil, true, false), Subcommands: []*cli.Command{ { Name: "add", @@ -1139,7 +1156,7 @@ var app = &cli.App{ UsageText: createUsageText("data tag ids add", []string{ dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs, - }, false), + }, false, false), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), }, @@ -1149,7 +1166,7 @@ var app = &cli.App{ UsageText: createUsageText("data tag ids remove", []string{ dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs, - }, false), + }, false, false), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), }, @@ -1158,14 +1175,14 @@ var app = &cli.App{ { Name: "filter", Usage: "adds or removes tags from binary data by filter", - UsageText: createUsageText("data tag filter", []string{dataFlagTags}, false), + UsageText: createUsageText("data tag filter", []string{dataFlagTags}, false, false), Subcommands: []*cli.Command{ { Name: "add", Usage: "adds tags to binary data by filter", UsageText: createUsageText("data tag filter add", []string{ dataFlagTags, - }, false), + }, false, false), Flags: dataTagByFilterFlags, Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, @@ -1174,7 +1191,7 @@ var app = &cli.App{ Usage: "removes tags from binary data by filter", UsageText: createUsageText("data tag filter remove", []string{ dataFlagTags, - }, false), + }, false, false), Flags: dataTagByFilterFlags, Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, @@ -1192,7 +1209,7 @@ var app = &cli.App{ { Name: "create", Usage: "create a new dataset", - UsageText: createUsageText("dataset create", []string{generalFlagOrgID, datasetFlagName}, false), + UsageText: createUsageText("dataset create", []string{generalFlagOrgID, datasetFlagName}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -1211,7 +1228,7 @@ var app = &cli.App{ Name: "rename", Usage: "rename an existing dataset", UsageText: createUsageText("dataset rename", - []string{datasetFlagDatasetID, datasetFlagName}, false), + []string{datasetFlagDatasetID, datasetFlagName}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1246,7 +1263,7 @@ var app = &cli.App{ { Name: "delete", Usage: "delete a dataset", - UsageText: createUsageText("dataset delete", []string{datasetFlagDatasetID}, false), + UsageText: createUsageText("dataset delete", []string{datasetFlagDatasetID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1260,7 +1277,7 @@ var app = &cli.App{ Name: "export", Usage: "download data from a dataset", UsageText: createUsageText("dataset export", - []string{dataFlagDestination, datasetFlagDatasetID}, true, datasetFlagIncludeJSONLines, dataFlagParallelDownloads), + []string{dataFlagDestination, datasetFlagDatasetID}, true, false, datasetFlagIncludeJSONLines, dataFlagParallelDownloads), Flags: []cli.Flag{ &cli.PathFlag{ Name: dataFlagDestination, @@ -1295,7 +1312,7 @@ var app = &cli.App{ { Name: "data", Usage: "add or remove data from datasets", - UsageText: createUsageText("dataset data", nil, true), + UsageText: createUsageText("dataset data", nil, true, false), Subcommands: []*cli.Command{ { Name: "add", @@ -1307,7 +1324,7 @@ var app = &cli.App{ UsageText: createUsageText("dataset data add ids", []string{ datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs, - }, false), + }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1335,7 +1352,7 @@ var app = &cli.App{ { Name: "filter", Usage: "adds binary data from the specified filter to dataset", - UsageText: createUsageText("dataset data add filter", []string{datasetFlagDatasetID}, true), + UsageText: createUsageText("dataset data add filter", []string{datasetFlagDatasetID}, true, false), Flags: append([]cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1357,7 +1374,7 @@ var app = &cli.App{ Name: "remove", Usage: "removes binary data with file IDs in a single org and location from dataset", UsageText: createUsageText("dataset data remove", - []string{datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false), + []string{datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false), // TODO(RSDK-9286) do we need to ask for og and location here? Flags: []cli.Flag{ &cli.StringFlag{ @@ -1401,7 +1418,7 @@ var app = &cli.App{ Name: "managed", Usage: "submits training job on data in Viam cloud with a Viam-managed training script", UsageText: createUsageText("train submit managed", - []string{datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, trainFlagModelType, trainFlagModelLabels}, true), + []string{datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, trainFlagModelType, trainFlagModelLabels}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1449,7 +1466,7 @@ var app = &cli.App{ []string{ datasetFlagDatasetID, generalFlagOrgID, trainFlagModelName, mlTrainingFlagName, mlTrainingFlagVersion, mlTrainingFlagArgs, - }, true), + }, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1497,7 +1514,7 @@ var app = &cli.App{ []string{ datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, mlTrainingFlagPath, mlTrainingFlagName, mlTrainingFlagArgs, - }, true), + }, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1569,7 +1586,7 @@ var app = &cli.App{ { Name: "get", Usage: "gets training job from Viam cloud based on training job ID", - UsageText: createUsageText("train get", []string{trainFlagJobID}, false), + UsageText: createUsageText("train get", []string{trainFlagJobID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: trainFlagJobID, @@ -1582,7 +1599,7 @@ var app = &cli.App{ { Name: "logs", Usage: "gets training job logs from Viam cloud based on training job ID", - UsageText: createUsageText("train logs", []string{trainFlagJobID}, false), + UsageText: createUsageText("train logs", []string{trainFlagJobID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: trainFlagJobID, @@ -1595,7 +1612,7 @@ var app = &cli.App{ { Name: "cancel", Usage: "cancels training job in Viam cloud based on training job ID", - UsageText: createUsageText("train cancel", []string{trainFlagJobID}, false), + UsageText: createUsageText("train cancel", []string{trainFlagJobID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: trainFlagJobID, @@ -1608,7 +1625,7 @@ var app = &cli.App{ { Name: "list", Usage: "list training jobs in Viam cloud based on organization ID", - UsageText: createUsageText("train list", []string{generalFlagOrgID}, true), + UsageText: createUsageText("train list", []string{generalFlagOrgID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -1656,7 +1673,7 @@ var app = &cli.App{ { Name: "create", Usage: "create an api-key for your machine", - UsageText: createUsageText("machines api-key create", []string{generalFlagMachineID}, true), + UsageText: createUsageText("machines api-key create", []string{generalFlagMachineID}, true, false), Flags: []cli.Flag{ &AliasStringFlag{ cli.StringFlag{ @@ -1683,7 +1700,7 @@ var app = &cli.App{ { Name: "status", Usage: "display machine status", - UsageText: createUsageText("machines status", []string{generalFlagMachine}, true), + UsageText: createUsageText("machines status", []string{generalFlagMachine}, true, false), // TODO(RSDK-9286) - do we need to ask for all three of these? Flags: []cli.Flag{ &cli.StringFlag{ @@ -1710,7 +1727,7 @@ var app = &cli.App{ Name: "logs", Aliases: []string{"log"}, Usage: "display machine logs", - UsageText: createUsageText("machines logs", []string{generalFlagMachine}, true), + UsageText: createUsageText("machines logs", []string{generalFlagMachine}, true, false), // TODO(RSDK-9286) do we need to ask for og and location and machine here? Flags: []cli.Flag{ &cli.StringFlag{ @@ -1758,7 +1775,7 @@ var app = &cli.App{ { Name: "status", Usage: "display part status", - UsageText: createUsageText("machines part status", []string{generalFlagMachine, generalFlagPart}, true), + UsageText: createUsageText("machines part status", []string{generalFlagMachine, generalFlagPart}, true, false), // TODO(RSDK-9286) do we need to ask for og and location and machine and part here? Flags: []cli.Flag{ &cli.StringFlag{ @@ -1792,7 +1809,7 @@ var app = &cli.App{ Name: "logs", Aliases: []string{"log"}, Usage: "display part logs", - UsageText: createUsageText("machines part logs", []string{generalFlagMachine, generalFlagPart}, true), + UsageText: createUsageText("machines part logs", []string{generalFlagMachine, generalFlagPart}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, @@ -1839,7 +1856,7 @@ var app = &cli.App{ Name: "restart", Aliases: []string{}, Usage: "request part restart", - UsageText: createUsageText("machines part restart", []string{generalFlagMachine, generalFlagPart}, true), + UsageText: createUsageText("machines part restart", []string{generalFlagMachine, generalFlagPart}, true, false), // TODO(RSDK-9286) revisit flags Flags: []cli.Flag{ &cli.StringFlag{ @@ -1874,7 +1891,7 @@ var app = &cli.App{ Usage: "run a command on a machine part", UsageText: createUsageText("machines part run", []string{ generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart, - }, true, ""), + }, true, false, ""), Flags: []cli.Flag{ &AliasStringFlag{ cli.StringFlag{ @@ -1920,7 +1937,7 @@ var app = &cli.App{ Usage: "start a shell on a machine part", Description: `In order to use the shell command, the machine must have a valid shell type service.`, UsageText: createUsageText( - "machines part shell", []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart}, false, + "machines part shell", []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart}, false, false, ), // TODO(RSDK-9286) do we need to ask for og and location and machine and part here? Flags: []cli.Flag{ @@ -1977,7 +1994,7 @@ Copy multiple files from the machine to a local destination with recursion and k UsageText: createUsageText( "machines part cp", []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart}, - true, + true, false, "[-p] [-r] source ([machine:]files) ... target ([machine:]files"), Flags: []cli.Flag{ &cli.StringFlag{ @@ -2037,7 +2054,7 @@ you won't have to pass a namespace or org-id in future commands. Otherwise there and you will have to provide the org-id to future cli commands. You cannot make your module public until you claim an org-id. After creation, use 'viam module update' to push your new module to app.viam.com.`, - UsageText: createUsageText("module create", []string{generalFlagName}, true), + UsageText: createUsageText("module create", []string{generalFlagName}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagName, @@ -2123,7 +2140,7 @@ After creation, use 'viam module update' to push your new module to app.viam.com { Name: "update-models", Usage: "update a module's metadata file based on models it provides", - UsageText: createUsageText("module update-models", []string{moduleFlagBinary}, true), + UsageText: createUsageText("module update-models", []string{moduleFlagBinary}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2155,7 +2172,7 @@ Example uploading a custom tarball of your module: tar -czf packaged-module.tar.gz ./src requirements.txt run.sh viam module upload --version "0.1.0" --platform "linux/amd64" packaged-module.tar.gz `, - UsageText: createUsageText("module upload", []string{moduleFlagVersion, moduleFlagPlatform}, true, ""), + UsageText: createUsageText("module upload", []string{moduleFlagVersion, moduleFlagPlatform}, true, false, ""), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2245,7 +2262,7 @@ Example: { Name: "start", Usage: "start a remote build", - UsageText: createUsageText("module build start", []string{moduleBuildFlagVersion}, true), + UsageText: createUsageText("module build start", []string{moduleBuildFlagVersion}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleBuildFlagPath, @@ -2306,7 +2323,7 @@ Example: Name: "logs", Aliases: []string{"log"}, Usage: "get the logs from one of your cloud builds", - UsageText: createUsageText("module build logs", []string{moduleBuildFlagBuildID}, true), + UsageText: createUsageText("module build logs", []string{moduleBuildFlagBuildID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleBuildFlagBuildID, @@ -2360,7 +2377,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "reload", Usage: "build a module locally and run it on a target device. rebuild & restart if already running", - UsageText: createUsageText("module reload", []string{}, true), + UsageText: createUsageText("module reload", []string{}, true, false), Description: `Example invocations: # A full reload command. This will build your module, send the tarball to the machine with given part ID, @@ -2415,7 +2432,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "download", Usage: "download a module package from the registry", - UsageText: createUsageText("module download", []string{}, false), + UsageText: createUsageText("module download", []string{}, false, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagDestination, @@ -2449,7 +2466,7 @@ This won't work unless you have an existing installation of our GitHub app on yo Name: "export", Usage: "download a package from Viam cloud", UsageText: createUsageText("packages export", - []string{packageFlagType}, false), + []string{packageFlagType}, false, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagDestination, @@ -2484,7 +2501,7 @@ This won't work unless you have an existing installation of our GitHub app on yo []string{ packageFlagPath, generalFlagOrgID, generalFlagName, packageFlagVersion, packageFlagType, - }, false), + }, false, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagPath, @@ -2530,7 +2547,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "upload", Usage: "upload ML training scripts for custom ML training", - UsageText: createUsageText("training-script upload", []string{mlTrainingFlagPath, mlTrainingFlagName}, true), + UsageText: createUsageText("training-script upload", []string{mlTrainingFlagPath, mlTrainingFlagName}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: mlTrainingFlagPath, @@ -2577,9 +2594,11 @@ This won't work unless you have an existing installation of our GitHub app on yo Action: createCommandWithT[mlTrainingUploadArgs](MLTrainingUploadAction), }, { - Name: "update", - Usage: "update ML training scripts for custom ML training", - UsageText: createUsageText("training-script update", []string{generalFlagOrgID, mlTrainingFlagName, mlTrainingFlagVisibility}, true), + Name: "update", + Usage: "update ML training scripts for custom ML training", + UsageText: createUsageText( + "training-script update", []string{generalFlagOrgID, mlTrainingFlagName, mlTrainingFlagVisibility}, true, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2623,7 +2642,7 @@ This won't work unless you have an existing installation of our GitHub app on yo generalFlagOrgID, authApplicationFlagName, authApplicationFlagOriginURIs, authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, - }, false), + }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2660,7 +2679,7 @@ This won't work unless you have an existing installation of our GitHub app on yo generalFlagOrgID, authApplicationFlagApplicationID, authApplicationFlagName, authApplicationFlagOriginURIs, authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, - }, false), + }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2701,7 +2720,7 @@ This won't work unless you have an existing installation of our GitHub app on yo UsageText: createUsageText("auth-app get", []string{ generalFlagOrgID, authApplicationFlagApplicationID, - }, false), + }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, From 74d6e326d18b2578b9484f55b30f5666fa392f99 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 13:18:15 -0500 Subject: [PATCH 10/38] locations usage text --- cli/app.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/app.go b/cli/app.go index 6add3f8413d..a9166b609c7 100644 --- a/cli/app.go +++ b/cli/app.go @@ -812,8 +812,9 @@ var app = &cli.App{ HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "list", - Usage: "list locations for the current user", + Name: "list", + Usage: "list locations for the current user", + UsageText: createUsageText("locations list", nil, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, @@ -824,13 +825,14 @@ var app = &cli.App{ Action: createCommandWithT[listLocationsArgs](ListLocationsAction), }, { - Name: "api-key", - Usage: "work with an api-key for your location", + Name: "api-key", + Usage: "work with an api-key for your location", + UsageText: createUsageText("locations api-key", nil, false, true), Subcommands: []*cli.Command{ { Name: "create", Usage: "create an api key for your location", - UsageText: createUsageText("api-key create", []string{generalFlagOrgID}, true, false), + UsageText: createUsageText("locations api-key create", []string{generalFlagLocationID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagLocationID, @@ -843,8 +845,8 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: generalFlagOrgID, - Usage: "the org-id to attach the key to" + - "If not provided, will attempt to attach itself to the org of the location if only one org is attached to the location", + Usage: "the org-id to attach the key to", + DefaultText: "will attempt to attach key to the org of the location if only one org is attached to the location", }, }, Action: createCommandWithT[locationAPIKeyCreateArgs](LocationAPIKeyCreateAction), From 217141d530157defde25276423ca9cf449917057 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 13:19:54 -0500 Subject: [PATCH 11/38] make lint --- cli/app.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/app.go b/cli/app.go index a9166b609c7..33ffac49cee 100644 --- a/cli/app.go +++ b/cli/app.go @@ -359,7 +359,7 @@ func createCommandWithT[T any](f func(*cli.Context, T) error) func(*cli.Context) // createUsageText is a helper for formatting UsageTexts. The created UsageText // contains "viam", the command, requiredFlags, "[other options]" if unrequiredOptions -// is true, " [command options]" if subcommand is true, and all passed-in +// is true, " [command options]" if subcommand is true, and all passed-in // arguments in that order. func createUsageText(command string, requiredFlags []string, unrequiredOptions, subcommand bool, arguments ...string) string { formatted := []string{"viam", command} @@ -793,8 +793,8 @@ var app = &cli.App{ Usage: "the org to create an api key for", }, &cli.StringFlag{ - Name: generalFlagName, - Usage: "the name of the key", + Name: generalFlagName, + Usage: "the name of the key", DefaultText: "login info with current time", }, }, @@ -844,8 +844,8 @@ var app = &cli.App{ Usage: "the name of the key (defaults to your login info with the current time)", }, &cli.StringFlag{ - Name: generalFlagOrgID, - Usage: "the org-id to attach the key to", + Name: generalFlagOrgID, + Usage: "the org-id to attach the key to", DefaultText: "will attempt to attach key to the org of the location if only one org is attached to the location", }, }, From 1260c946b73668903e68393429b91385f54bb1d4 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 13:26:09 -0500 Subject: [PATCH 12/38] add usagetext for profiles commands with required flags --- cli/app.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/cli/app.go b/cli/app.go index 33ffac49cee..f25ce7631ea 100644 --- a/cli/app.go +++ b/cli/app.go @@ -858,11 +858,13 @@ var app = &cli.App{ { Name: "profiles", Usage: "work with CLI profiles", + UsageText: createUsageText("profiles", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "update", - Usage: "update an existing profile for authentication, or add it if it doesn't exist", + Name: "update", + Usage: "update an existing profile for authentication, or add it if it doesn't exist", + UsageText: createUsageText("profiles update", []string{profileFlagName, loginFlagKeyID, loginFlagKey}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: profileFlagName, @@ -883,8 +885,9 @@ var app = &cli.App{ Action: createCommandWithT[addOrUpdateProfileArgs](UpdateProfileAction), }, { - Name: "add", - Usage: "add a new profile for authentication (errors if the profile already exists)", + Name: "add", + Usage: "add a new profile for authentication (errors if the profile already exists)", + UsageText: createUsageText("profiles add", []string{profileFlagName, loginFlagKeyID, loginFlagKey}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: profileFlagName, @@ -905,13 +908,15 @@ var app = &cli.App{ Action: createCommandWithT[addOrUpdateProfileArgs](AddProfileAction), }, { - Name: "list", - Usage: "list all existing profiles by name", - Action: createCommandWithT[emptyArgs](ListProfilesAction), + Name: "list", + Usage: "list all existing profiles by name", + UsageText: createUsageText("profiles list", nil, false, false), + Action: createCommandWithT[emptyArgs](ListProfilesAction), }, { - Name: "remove", - Usage: "remove an authentication profile", + Name: "remove", + Usage: "remove an authentication profile", + UsageText: createUsageText("profiles remove", []string{profileFlagName}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: profileFlagName, From 1e71c164e6696af9c458ccbc6f3cf67b0f5e88d0 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 8 Jan 2025 13:49:55 -0500 Subject: [PATCH 13/38] fix/standardize usagetext for data commands --- cli/app.go | 83 +++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/cli/app.go b/cli/app.go index f25ce7631ea..68ab25ba456 100644 --- a/cli/app.go +++ b/cli/app.go @@ -219,17 +219,16 @@ var commonFilterFlags = []cli.Flag{ Usage: "ISO-8601 timestamp in RFC3339 format indicating the end of the interval filter", }, &cli.StringSliceFlag{ - Name: dataFlagBboxLabels, - Usage: "bbox labels filter. " + - "accepts string labels corresponding to bounding boxes within images", + Name: dataFlagBboxLabels, + Usage: "bbox labels filter. accepts string labels corresponding to bounding boxes within images", }, } var dataTagByIDsFlags = []cli.Flag{ &cli.StringSliceFlag{ Name: dataFlagTags, - Required: true, Usage: "comma separated tags to add/remove to the data", + Required: true, }, &cli.StringFlag{ Name: generalFlagOrgID, @@ -931,11 +930,14 @@ var app = &cli.App{ { Name: "data", Usage: "work with data", + UsageText: createUsageText("data", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "export", - Usage: "download data from Viam cloud", + Name: "export", + Usage: "download data from Viam cloud", + UsageText: createUsageText("data export", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "binary", @@ -1016,12 +1018,13 @@ var app = &cli.App{ { Name: "delete", Usage: "delete data from Viam cloud", + UsageText: createUsageText("data delete", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "binary", Usage: "delete binary data from Viam cloud", - UsageText: createUsageText("data delete binary", nil, true, false), + UsageText: createUsageText("data delete binary", []string{dataFlagOrgIDs, dataFlagStart, dataFlagEnd}, true, false), Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: dataFlagOrgIDs, @@ -1109,9 +1112,10 @@ var app = &cli.App{ }, }, { - Name: "database", - Usage: "interact with a MongoDB Atlas Data Federation instance", - UsageText: createUsageText("data database", nil, true, false), + Name: "database", + Usage: "interact with a MongoDB Atlas Data Federation instance", + UsageText: createUsageText("data database", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "configure", @@ -1148,59 +1152,56 @@ var app = &cli.App{ }, }, { - Name: "tag", - Usage: "tag binary data by filter or ids", - UsageText: createUsageText("data tag", nil, true, false), + Name: "tag", + Usage: "tag binary data by filter or ids", + UsageText: createUsageText("data tag", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "ids", - Usage: "adds or removes tags from binary data by file ids for a given org and location", - UsageText: createUsageText("data tag ids", nil, true, false), + Name: "ids", + Usage: "adds or removes tags from binary data by file ids for a given org and location", + UsageText: createUsageText("data tag ids", nil, true, false), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "add", Usage: "adds tags to binary data by file ids for a given org and location", - UsageText: createUsageText("data tag ids add", []string{ - dataFlagTags, generalFlagOrgID, - dataFlagLocationID, dataFlagFileIDs, - }, false, false), + UsageText: createUsageText( + "data tag ids add", []string{dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + ), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), }, { Name: "remove", Usage: "removes tags from binary data by file ids for a given org and location", - UsageText: createUsageText("data tag ids remove", []string{ - dataFlagTags, generalFlagOrgID, - dataFlagLocationID, dataFlagFileIDs, - }, false, false), + UsageText: createUsageText( + "data tag ids remove", []string{dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + ), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), }, }, }, { - Name: "filter", - Usage: "adds or removes tags from binary data by filter", - UsageText: createUsageText("data tag filter", []string{dataFlagTags}, false, false), + Name: "filter", + Usage: "adds or removes tags from binary data by filter", + UsageText: createUsageText("data tag filter", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "add", - Usage: "adds tags to binary data by filter", - UsageText: createUsageText("data tag filter add", []string{ - dataFlagTags, - }, false, false), - Flags: dataTagByFilterFlags, - Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), + Name: "add", + Usage: "adds tags to binary data by filter", + UsageText: createUsageText("data tag filter add", []string{dataFlagTags}, false, false), + Flags: dataTagByFilterFlags, + Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, { - Name: "remove", - Usage: "removes tags from binary data by filter", - UsageText: createUsageText("data tag filter remove", []string{ - dataFlagTags, - }, false, false), - Flags: dataTagByFilterFlags, - Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), + Name: "remove", + Usage: "removes tags from binary data by filter", + UsageText: createUsageText("data tag filter remove", []string{dataFlagTags}, false, false), + Flags: dataTagByFilterFlags, + Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, }, }, From ac458977888a3dc11f2b5dcf53b7012fca00af24 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 9 Jan 2025 09:56:13 -0500 Subject: [PATCH 14/38] add usagetext to dataset commands, remove unnecessary code --- cli/app.go | 45 +++++++++++++++++++++++---------------------- cli/dataset.go | 1 - 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cli/app.go b/cli/app.go index 68ab25ba456..13e268e4829 100644 --- a/cli/app.go +++ b/cli/app.go @@ -1212,6 +1212,7 @@ var app = &cli.App{ { Name: "dataset", Usage: "work with datasets", + UsageText: createUsageText("dataset", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -1259,11 +1260,11 @@ var app = &cli.App{ Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: datasetFlagDatasetIDs, - Usage: "dataset IDs of datasets to be listed", + Usage: fmt.Sprintf("dataset IDs of datasets to be listed, required if '%s' is not given", generalFlagOrgID), }, &cli.StringFlag{ Name: generalFlagOrgID, - Usage: "org ID for which datasets will be listed", + Usage: fmt.Sprintf("org ID for which datasets will be listed, required if '%s' is not given", datasetFlagDatasetIDs), }, }, Action: createCommandWithT[datasetListArgs](DatasetListAction), @@ -1285,7 +1286,7 @@ var app = &cli.App{ Name: "export", Usage: "download data from a dataset", UsageText: createUsageText("dataset export", - []string{dataFlagDestination, datasetFlagDatasetID}, true, false, datasetFlagIncludeJSONLines, dataFlagParallelDownloads), + []string{dataFlagDestination, datasetFlagDatasetID}, true, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: dataFlagDestination, @@ -1298,16 +1299,13 @@ var app = &cli.App{ Usage: "dataset ID of the dataset to be downloaded", }, &cli.BoolFlag{ - Name: datasetFlagIncludeJSONLines, - Required: false, - Usage: "option to include JSON Lines files for local testing", - Value: false, + Name: datasetFlagIncludeJSONLines, + Usage: "option to include JSON Lines files for local testing", }, &cli.UintFlag{ - Name: dataFlagParallelDownloads, - Required: false, - Usage: "number of download requests to make in parallel", - Value: 100, + Name: dataFlagParallelDownloads, + Usage: "number of download requests to make in parallel", + Value: 100, }, &cli.UintFlag{ Name: dataFlagTimeout, @@ -1318,21 +1316,23 @@ var app = &cli.App{ Action: createCommandWithT[datasetDownloadArgs](DatasetDownloadAction), }, { - Name: "data", - Usage: "add or remove data from datasets", - UsageText: createUsageText("dataset data", nil, true, false), + Name: "data", + Usage: "add or remove data from datasets", + UsageText: createUsageText("dataset data", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "add", - Usage: "adds binary data either by IDs or filter to dataset", + Name: "add", + Usage: "adds binary data either by IDs or filter to dataset", + UsageText: createUsageText("dataset data add", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "ids", Usage: "adds binary data with file IDs in a single org and location to dataset", - UsageText: createUsageText("dataset data add ids", []string{ - datasetFlagDatasetID, generalFlagOrgID, - dataFlagLocationID, dataFlagFileIDs, - }, false, false), + UsageText: createUsageText( + "dataset data add ids", []string{datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1381,8 +1381,9 @@ var app = &cli.App{ { Name: "remove", Usage: "removes binary data with file IDs in a single org and location from dataset", - UsageText: createUsageText("dataset data remove", - []string{datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false), + UsageText: createUsageText( + "dataset data remove", []string{datasetFlagDatasetID, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + ), // TODO(RSDK-9286) do we need to ask for og and location here? Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/cli/dataset.go b/cli/dataset.go index 6029e45d197..6e027aee8a2 100644 --- a/cli/dataset.go +++ b/cli/dataset.go @@ -99,7 +99,6 @@ func DatasetListAction(c *cli.Context, args datasetListArgs) error { datasetIDs := args.DatasetIDs orgID := args.OrgID - // TODO(RSDK-9288) - see if we can make this clearer to users from the outset if orgID != "" && datasetIDs != nil { return errors.New("must specify either dataset IDs or organization ID, got both") } From 2eb8d38a76c57b11c3972428894d29da4124ccf0 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 9 Jan 2025 10:21:44 -0500 Subject: [PATCH 15/38] standardize train subcommands --- cli/app.go | 90 +++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/cli/app.go b/cli/app.go index 13e268e4829..81d241c4ab2 100644 --- a/cli/app.go +++ b/cli/app.go @@ -1416,18 +1416,21 @@ var app = &cli.App{ { Name: "train", Usage: "train on data", - UsageText: "viam train [other options]", + UsageText: createUsageText("train", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "submit", - Usage: "submits training job on data in Viam cloud", + Name: "submit", + Usage: "submits training job on data in Viam cloud", + UsageText: createUsageText("train submit", nil, false, true), Subcommands: []*cli.Command{ { Name: "managed", Usage: "submits training job on data in Viam cloud with a Viam-managed training script", UsageText: createUsageText("train submit managed", - []string{datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, trainFlagModelType, trainFlagModelLabels}, true, false), + []string{datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, trainFlagModelType, trainFlagModelLabels}, + true, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1445,37 +1448,36 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: trainFlagModelType, - Usage: "type of model to train. can be one of " + - "[single_label_classification, multi_label_classification, or object_detection]", + Name: trainFlagModelType, + Usage: "type of model to train. can be one of [single_label_classification, multi_label_classification, or object_detection]", Required: true, }, &cli.StringSliceFlag{ - Name: trainFlagModelLabels, - Usage: "labels to train on. " + - "this will either be classification or object detection labels", + Name: trainFlagModelLabels, + Usage: "labels to train on. this will either be classification or object detection labels", Required: true, }, &cli.StringFlag{ - Name: trainFlagModelVersion, - Usage: "version of ML model. defaults to current timestamp if unspecified.", + Name: trainFlagModelVersion, + Usage: "version of ML model", + DefaultText: "current timestamp", }, }, Action: createCommandWithT[mlSubmitTrainingJobArgs](MLSubmitTrainingJob), }, { - Name: "custom", - Usage: "submits custom training job on data in Viam cloud", + Name: "custom", + Usage: "submits custom training job on data in Viam cloud", + UsageText: createUsageText("train submit custom", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "from-registry", Usage: "submits custom training job with an existing training script in the registry on data in Viam cloud", - UsageText: createUsageText("train submit custom from-registry", - []string{ - datasetFlagDatasetID, generalFlagOrgID, trainFlagModelName, - mlTrainingFlagName, mlTrainingFlagVersion, mlTrainingFlagArgs, - }, true, false), + []string{datasetFlagDatasetID, generalFlagOrgID, trainFlagModelName, mlTrainingFlagName, mlTrainingFlagVersion}, + true, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1499,7 +1501,7 @@ var app = &cli.App{ &cli.StringFlag{ Name: mlTrainingFlagName, Usage: "registry name of the ML training script to use for training, " + - "which should be formatted as prefix:itemname where prefix is either the org ID or the namespace.", + "should be formatted as prefix:itemname where prefix is either the org ID or the namespace.", Required: true, }, &cli.StringFlag{ @@ -1508,10 +1510,8 @@ var app = &cli.App{ Required: true, }, &cli.StringSliceFlag{ - Name: mlTrainingFlagArgs, - Usage: "optional command line arguments to run the training script with " + - "which should be formatted as option1=value1,option2=value2", - Required: false, + Name: mlTrainingFlagArgs, + Usage: "command line arguments to run the training script with, should be formatted as option1=value1,option2=value2", }, }, Action: createCommandWithT[mlSubmitCustomTrainingJobArgs](MLSubmitCustomTrainingJob), @@ -1520,10 +1520,9 @@ var app = &cli.App{ Name: "with-upload", Usage: "submits custom training job with an upload training script on data in Viam cloud", UsageText: createUsageText("train submit custom with-upload", - []string{ - datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, - mlTrainingFlagPath, mlTrainingFlagName, mlTrainingFlagArgs, - }, true, false), + []string{generalFlagOrgID, datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, mlTrainingFlagPath, mlTrainingFlagName}, + true, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: datasetFlagDatasetID, @@ -1540,9 +1539,8 @@ var app = &cli.App{ Usage: "version of ML model. defaults to current timestamp if unspecified.", }, &cli.StringFlag{ - Name: mlTrainingFlagURL, - Usage: "url of Github repository associated with the training scripts", - Required: false, + Name: mlTrainingFlagURL, + Usage: "url of Github repository associated with the training scripts", }, &cli.StringFlag{ Name: mlTrainingFlagPath, @@ -1557,7 +1555,7 @@ var app = &cli.App{ &cli.StringFlag{ Name: trainFlagModelOrgID, Required: true, - Usage: "organization ID to upload and run training job", + Usage: "org ID to upload and run training job", }, &cli.StringFlag{ Name: mlTrainingFlagName, @@ -1565,25 +1563,20 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagVersion, - Usage: "version of the ML training script to upload. defaults to current timestamp if unspecified.", - Required: false, + Name: mlTrainingFlagVersion, + Usage: "version of the ML training script to upload. defaults to current timestamp if unspecified.", }, &cli.StringFlag{ - Name: mlTrainingFlagFramework, - Usage: "framework of the ML training script to upload, can be: " + strings.Join(modelFrameworks, ", "), - Required: false, + Name: mlTrainingFlagFramework, + Usage: "framework of the ML training script to upload, can be: [" + strings.Join(modelFrameworks, ", ") + "]", }, &cli.StringFlag{ - Name: trainFlagModelType, - Usage: "task type of the ML training script to upload, can be: " + strings.Join(modelTypes, ", "), - Required: false, + Name: trainFlagModelType, + Usage: "task type of the ML training script to upload, can be: [" + strings.Join(modelTypes, ", ") + "]", }, &cli.StringSliceFlag{ - Name: mlTrainingFlagArgs, - Usage: "optional command line arguments to run the training script with " + - "which should be formatted as option1=value1,option2=value2", - Required: false, + Name: mlTrainingFlagArgs, + Usage: "command line arguments to run the training script with, should be formatted as option1=value1,option2=value2", }, }, Action: createCommandWithT[mlSubmitCustomTrainingJobWithUploadArgs](MLSubmitCustomTrainingJobWithUpload), @@ -1642,10 +1635,9 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: trainFlagJobStatus, - Usage: "training status to filter for. can be one of " + allTrainingStatusValues(), - Required: false, - Value: defaultTrainingStatus(), + Name: trainFlagJobStatus, + Usage: "training status to filter for. can be: " + allTrainingStatusValues(), + Value: defaultTrainingStatus(), }, }, Action: createCommandWithT[dataListTrainingJobsArgs](DataListTrainingJobs), From f3835155ff4c140e51b1904a945488fe163f814f Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 9 Jan 2025 11:45:44 -0500 Subject: [PATCH 16/38] standardize machine subcommands --- cli/app.go | 83 +++++++++++++++++++++++++++++++-------------------- cli/client.go | 16 +++++----- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/cli/app.go b/cli/app.go index 81d241c4ab2..c3d951fa96a 100644 --- a/cli/app.go +++ b/cli/app.go @@ -53,6 +53,7 @@ const ( generalFlagAliasPartName = "part-name" generalFlagPartID = "part-id" generalFlagName = "name" + generalFlagMethod = "method" moduleFlagLanguage = "language" moduleFlagPublicNamespace = "public-namespace" @@ -112,7 +113,6 @@ const ( dataFlagResourceSubtype = "resource-subtype" dataFlagComponentName = "component-name" dataFlagResourceName = "resource-name" - dataFlagMethod = "method" dataFlagMimeTypes = "mime-types" dataFlagStart = "start" dataFlagEnd = "end" @@ -203,7 +203,7 @@ var commonFilterFlags = []cli.Flag{ Usage: "component name filter", }, &cli.StringFlag{ - Name: dataFlagMethod, + Name: generalFlagMethod, Usage: "method filter", }, &cli.StringSliceFlag{ @@ -974,7 +974,7 @@ var app = &cli.App{ generalFlagPartID, dataFlagResourceName, dataFlagResourceSubtype, - dataFlagMethod, + generalFlagMethod, }, true, false), Flags: []cli.Flag{ &cli.PathFlag{ @@ -998,7 +998,7 @@ var app = &cli.App{ Usage: "resource subtype (sometimes called 'component type')", }, &cli.StringFlag{ - Name: dataFlagMethod, + Name: generalFlagMethod, Required: true, Usage: "method name", }, @@ -1076,7 +1076,7 @@ var app = &cli.App{ Usage: "component name filter", }, &cli.StringFlag{ - Name: dataFlagMethod, + Name: generalFlagMethod, Usage: "method filter", }, &cli.StringSliceFlag{ @@ -1257,6 +1257,7 @@ var app = &cli.App{ Usage: "list dataset information from specified IDs or for an org ID", UsageText: fmt.Sprintf("viam dataset list [--%s=<%s> | --%s=<%s>]", datasetFlagDatasetIDs, datasetFlagDatasetIDs, generalFlagOrgID, generalFlagOrgID), + Description: "In order to list datasets, an org ID or a list of dataset IDs is required", Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: datasetFlagDatasetIDs, @@ -1648,11 +1649,13 @@ var app = &cli.App{ Name: "machines", Aliases: []string{"machine", "robots", "robot"}, Usage: "work with machines", + UsageText: createUsageText("machines", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "list", - Usage: "list machines in an organization and location", + Name: "list", + Usage: "list machines in an organization and location", + UsageText: createUsageText("machines list", nil, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, @@ -1668,8 +1671,10 @@ var app = &cli.App{ Action: createCommandWithT[listRobotsActionArgs](ListRobotsAction), }, { - Name: "api-key", - Usage: "work with a machine's api keys", + Name: "api-key", + Usage: "work with a machine's api keys", + UsageText: createUsageText("machines api-key", nil, false, true), + HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "create", @@ -1685,13 +1690,14 @@ var app = &cli.App{ }, }, &cli.StringFlag{ - Name: generalFlagName, - Usage: "the name of the key (defaults to your login info with the current time)", + Name: generalFlagName, + Usage: "the name of the key", + DefaultText: "login info with the current time", }, &cli.StringFlag{ - Name: generalFlagOrgID, - Usage: "the org-id to attach this api-key to. If not provided, " + - "we will attempt to use the org attached to the machine if only one exists", + Name: generalFlagOrgID, + Usage: "the org-id to attach this api-key to.", + DefaultText: "the org attached to the machine if only one exists", }, }, Action: createCommandWithT[robotAPIKeyCreateArgs](RobotAPIKeyCreateAction), @@ -1771,6 +1777,7 @@ var app = &cli.App{ { Name: "part", Usage: "work with a machine part", + UsageText: createUsageText("machines part", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -1855,7 +1862,6 @@ var app = &cli.App{ }, { Name: "restart", - Aliases: []string{}, Usage: "request part restart", UsageText: createUsageText("machines part restart", []string{generalFlagMachine, generalFlagPart}, true, false), // TODO(RSDK-9286) revisit flags @@ -1890,9 +1896,11 @@ var app = &cli.App{ { Name: "run", Usage: "run a command on a machine part", - UsageText: createUsageText("machines part run", []string{ - generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart, - }, true, false, ""), + UsageText: createUsageText( + "machines part run", + []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart, generalFlagMethod}, + true, false, + ), Flags: []cli.Flag{ &AliasStringFlag{ cli.StringFlag{ @@ -1930,16 +1938,22 @@ var app = &cli.App{ Name: runFlagStream, Aliases: []string{"s"}, }, + &cli.StringFlag{ + Name: generalFlagMethod, + Usage: "service method formatted as: '.' or '/'", + Required: false, // should be required but set as false to ensure backwards capability + }, }, - Action: createCommandWithT[robotsPartRunArgs](RobotsPartRunAction), + Action: createCommandWithT[machinesPartRunArgs](MachinesPartRunAction), }, { - Name: "shell", - Usage: "start a shell on a machine part", - Description: `In order to use the shell command, the machine must have a valid shell type service.`, - UsageText: createUsageText( - "machines part shell", []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart}, false, false, - ), + Name: "shell", + Usage: "start a shell on a machine part", + Description: ` +In order to use the shell command, the machine must have a valid shell type service. +Organization and location are required flags if the machine/part name are not unique across your account. +`, + UsageText: createUsageText("machines part shell", []string{generalFlagMachine, generalFlagPart}, false, false), // TODO(RSDK-9286) do we need to ask for og and location and machine and part here? Flags: []cli.Flag{ &cli.StringFlag{ @@ -1952,13 +1966,17 @@ var app = &cli.App{ }, &AliasStringFlag{ cli.StringFlag{ - Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Name: generalFlagMachine, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Required: true, }, }, - &cli.StringFlag{ - Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + &AliasStringFlag{ + cli.StringFlag{ + Name: generalFlagPart, + Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Required: true, + }, }, }, Action: createCommandWithT[robotsPartShellArgs](RobotsPartShellAction), @@ -1966,7 +1984,6 @@ var app = &cli.App{ { Name: "cp", Usage: "copy files to and from a machine part", - Description: ` In order to use the cp command, the machine must have a valid shell type service. Specifying ~ or a blank destination for the machine will use the home directory of the user @@ -1994,9 +2011,9 @@ Copy multiple files from the machine to a local destination with recursion and k `, UsageText: createUsageText( "machines part cp", - []string{generalFlagOrganization, generalFlagLocation, generalFlagMachine, generalFlagPart}, + []string{generalFlagMachine, generalFlagPart}, true, false, - "[-p] [-r] source ([machine:]files) ... target ([machine:]files"), + "... "), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, diff --git a/cli/client.go b/cli/client.go index 8ae9e82b206..028fa69d580 100644 --- a/cli/client.go +++ b/cli/client.go @@ -561,7 +561,7 @@ func ListLocationsAction(c *cli.Context, args listLocationsArgs) error { return nil } orgStr := args.Organization - if orgStr == "" && c.Args().First() != "" { + if orgStr == "" { orgStr = c.Args().First() } if orgStr == "" { @@ -984,20 +984,22 @@ func (c *viamClient) robotPartRestart(cCtx *cli.Context, args robotsPartRestartA return nil } -type robotsPartRunArgs struct { +type machinesPartRunArgs struct { Organization string Location string Machine string Part string Data string Stream time.Duration + Method string } -// RobotsPartRunAction is the corresponding Action for 'machines part run'. -func RobotsPartRunAction(c *cli.Context, args robotsPartRunArgs) error { - // TODO(RSDK-9288) - this is brittle and inconsistent with how most data is passed. - // Move this to being a flag (but make sure existing workflows still work!) - svcMethod := c.Args().First() +// MachinesPartRunAction is the corresponding Action for 'machines part run'. +func MachinesPartRunAction(c *cli.Context, args machinesPartRunArgs) error { + svcMethod := args.Method + if svcMethod == "" { + svcMethod = c.Args().First() + } if svcMethod == "" { return errors.New("service method required") } From 51ac5e1eb4485ae601093082b1ca698282c00a64 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 9 Jan 2025 13:29:56 -0500 Subject: [PATCH 17/38] standardize module subcommands --- cli/app.go | 90 +++++++++++++++++++++++------------------- cli/module_build.go | 14 +++---- cli/module_registry.go | 8 +--- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/cli/app.go b/cli/app.go index c3d951fa96a..0e4919cf739 100644 --- a/cli/app.go +++ b/cli/app.go @@ -79,7 +79,6 @@ const ( moduleBuildFlagRef = "ref" moduleBuildFlagCount = "count" moduleBuildFlagVersion = "version" - moduleBuildFlagBuildID = "id" moduleBuildFlagPlatform = "platform" moduleBuildFlagWait = "wait" moduleBuildFlagToken = "token" @@ -366,7 +365,7 @@ func createUsageText(command string, requiredFlags []string, unrequiredOptions, formatted = append(formatted, fmt.Sprintf("--%s=<%s>", flag, flag)) } if unrequiredOptions { - if requiredFlags == nil { + if len(requiredFlags) == 0 { formatted = append(formatted, "[options]") } else { formatted = append(formatted, "[other options]") @@ -2058,6 +2057,7 @@ Copy multiple files from the machine to a local destination with recursion and k { Name: "module", Usage: "manage your modules in Viam's registry", + UsageText: createUsageText("module", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -2095,8 +2095,9 @@ After creation, use 'viam module update' to push your new module to app.viam.com Action: createCommandWithT[createModuleActionArgs](CreateModuleAction), }, { - Name: "generate", - Usage: "generate a new modular resource via prompts", + Name: "generate", + Usage: "generate a new modular resource via prompts", + UsageText: createUsageText("module generate", nil, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagName, @@ -2143,8 +2144,9 @@ After creation, use 'viam module update' to push your new module to app.viam.com Action: createCommandWithT[generateModuleArgs](GenerateModuleAction), }, { - Name: "update", - Usage: "update a module's metadata on app.viam.com", + Name: "update", + Usage: "update a module's metadata on app.viam.com", + UsageText: createUsageText("module update", nil, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2231,13 +2233,12 @@ viam module upload --version "0.1.0" --platform "linux/amd64" packaged-module.ta darwin/arm64 (Apple silicon macs)`, Required: true, }, - &cli.StringFlag{ + &cli.StringSliceFlag{ Name: moduleFlagTags, - Usage: `Optional extra fields for constraining the platforms to which this binary + Usage: `extra fields for constraining the platforms to which this binary is deployed. Examples: distro:debian, distro:ubuntu, os_version:22.04, - os_codename:jammy. You can provide multiple tags in this field by separating - them with a comma. For a machine to use an upload, all tags must be satisified - as well as the --platform field.`, + os_codename:jammy. For a machine to use an upload, all tags must be + satisified as well as the --platform field.`, }, &cli.BoolFlag{ Name: moduleFlagForce, @@ -2247,9 +2248,11 @@ viam module upload --version "0.1.0" --platform "linux/amd64" packaged-module.ta Action: createCommandWithT[uploadModuleArgs](UploadModuleAction), }, { - Name: "build", - Usage: "build your module for different architectures using cloud runners", - UsageText: `Build your module on different operating systems and cpu architectures via cloud runners. + Name: "build", + Usage: "build your module for different architectures using cloud runners", + UsageText: createUsageText("module build", nil, false, true), + HideHelpCommand: true, + Description: `Build your module on different operating systems and cpu architectures via cloud runners. Make sure to add a "build" section to your meta.json. Example: { @@ -2265,8 +2268,9 @@ Example: `, Subcommands: []*cli.Command{ { - Name: "local", - Usage: "run your meta.json build command locally", + Name: "local", + Usage: "run your meta.json build command locally", + UsageText: createUsageText("module build local", nil, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2304,19 +2308,20 @@ Example: }, &cli.StringFlag{ Name: moduleBuildFlagWorkdir, - Usage: "use this to indicate that your meta.json is in a subdirectory of your repo." + " --module flag should be relative to this", + Usage: "use this to indicate that your meta.json is in a subdirectory of your repo. --module flag should be relative to this", Value: ".", }, &cli.StringSliceFlag{ Name: moduleBuildFlagPlatforms, - Usage: "list of platforms to build, e.g. linux/amd64,linux/arm64. Defaults to build.arch in meta.json.", + Usage: "list of platforms to build, e.g. linux/amd64,linux/arm64 (default: build.arch in meta.json)", }, }, Action: createCommandWithT[moduleBuildStartArgs](ModuleBuildStartAction), }, { - Name: "list", - Usage: "check on the status of your cloud builds", + Name: "list", + Usage: "check on the status of your cloud builds", + UsageText: createUsageText("module build list", nil, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2331,7 +2336,7 @@ Example: DefaultText: "all", }, &cli.StringFlag{ - Name: moduleBuildFlagBuildID, + Name: moduleFlagID, Usage: "restrict output to just return builds that match this id", }, }, @@ -2341,16 +2346,17 @@ Example: Name: "logs", Aliases: []string{"log"}, Usage: "get the logs from one of your cloud builds", - UsageText: createUsageText("module build logs", []string{moduleBuildFlagBuildID}, true, false), + UsageText: createUsageText("module build logs", []string{moduleFlagID}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ - Name: moduleBuildFlagBuildID, + Name: moduleFlagID, Usage: "build that you want to get the logs for", Required: true, }, &cli.StringFlag{ - Name: moduleBuildFlagPlatform, - Usage: "build platform to get the logs for. Ex: linux/arm64. If a platform is not provided, it returns logs for all platforms", + Name: moduleBuildFlagPlatform, + Usage: "build platform to get the logs for. Ex: linux/arm64.", + DefaultText: "all platforms", }, &cli.BoolFlag{ Name: moduleBuildFlagWait, @@ -2364,13 +2370,12 @@ Example: Action: createCommandWithT[moduleBuildLogsArgs](ModuleBuildLogsAction), }, { - Name: "link-repo", - Usage: "link a GitHub repository to your module", - //nolint:lll - UsageText: `This command connects a Viam module to a GitHub repository so that repo actions can trigger builds and releases of your module. + Name: "link-repo", + Usage: "link a GitHub repository to your module", + UsageText: createUsageText("module build link-repo", nil, true, false), + Description: `This command connects a Viam module to a GitHub repository so that repo actions can trigger builds and releases of your module. -This won't work unless you have an existing installation of our GitHub app on your GitHub org. (Details to follow). -`, +This won't work unless you have an existing installation of our GitHub app on your GitHub org. (Details to follow).`, // TODO(APP-3604): unhide when this is shipped externally Hidden: true, Flags: []cli.Flag{ @@ -2379,9 +2384,9 @@ This won't work unless you have an existing installation of our GitHub app on yo Usage: "ID of the oauth link between your GitHub org and Viam. Only required if you have more than one link", }, &cli.StringFlag{ - Name: moduleFlagPath, - Usage: "your module's ID in org-id:name or public-namespace:name format. " + - "If missing, we will try to get this from meta.json file in current directory", + Name: moduleFlagPath, + Usage: "your module's ID in org-id:name or public-namespace:name format", + DefaultText: "meta.json file in current directory", }, &cli.StringFlag{ Name: moduleBuildFlagRepo, @@ -2395,7 +2400,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "reload", Usage: "build a module locally and run it on a target device. rebuild & restart if already running", - UsageText: createUsageText("module reload", []string{}, true, false), + UsageText: createUsageText("module reload", nil, true, false), Description: `Example invocations: # A full reload command. This will build your module, send the tarball to the machine with given part ID, @@ -2412,7 +2417,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagPartID, - Usage: "part ID of machine. get from 'Live/Offline' dropdown in the web app, or leave it blank to use /etc/viam.json", + Usage: "part ID of machine. get from 'Live/Offline' dropdown in the web app", + DefaultText: "/etc/viam.json", }, &cli.StringFlag{ Name: moduleFlagPath, @@ -2424,8 +2430,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Usage: "name of module to restart. pass at most one of --name, --id", }, &cli.StringFlag{ - Name: moduleBuildFlagBuildID, - Usage: "ID of module to restart, for example viam:wifi-sensor", + Name: moduleFlagID, + Usage: "ID of module to restart, for example viam:wifi-sensor. pass at most one of --name, --id", }, &cli.BoolFlag{ Name: moduleBuildRestartOnly, @@ -2450,7 +2456,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "download", Usage: "download a module package from the registry", - UsageText: createUsageText("module download", []string{}, false, false), + UsageText: createUsageText("module download", []string{}, true, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagDestination, @@ -2459,7 +2465,8 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: moduleFlagID, - Usage: "module ID as org-id:name or namespace:name. if missing, will try to read from meta.json", + Usage: "module ID as org-id:name or namespace:name", + DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ Name: packageFlagVersion, @@ -2468,7 +2475,8 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: moduleFlagPlatform, - Usage: "platform like 'linux/amd64'. if missing, will use platform of the CLI binary", + Usage: "platform like 'linux/amd64'", + DefaultText: "platform of the CLI binary", }, }, Action: createCommandWithT[downloadModuleFlags](DownloadModuleAction), diff --git a/cli/module_build.go b/cli/module_build.go index c50c5158355..b933de7bddf 100644 --- a/cli/module_build.go +++ b/cli/module_build.go @@ -175,12 +175,10 @@ func ModuleBuildListAction(cCtx *cli.Context, args moduleBuildListArgs) error { } func (c *viamClient) moduleBuildListAction(cCtx *cli.Context, args moduleBuildListArgs) error { - var buildIDFilter *string + buildIDFilter := args.ID var moduleIDFilter string - // This will use the build id if present and fall back on the module manifest if not - if cCtx.IsSet(moduleBuildFlagBuildID) { - buildIDFilter = &args.ID - } else { + // Fall back on the module manifest build filter is not present. + if buildIDFilter == "" { manifestPath := args.Module manifest, err := loadManifest(manifestPath) if err != nil { @@ -197,7 +195,7 @@ func (c *viamClient) moduleBuildListAction(cCtx *cli.Context, args moduleBuildLi count := int32(args.Count) numberOfJobsToReturn = &count } - jobs, err := c.listModuleBuildJobs(moduleIDFilter, numberOfJobsToReturn, buildIDFilter) + jobs, err := c.listModuleBuildJobs(moduleIDFilter, numberOfJobsToReturn, &buildIDFilter) if err != nil { return err } @@ -656,7 +654,7 @@ func resolveTargetModule(c *cli.Context, manifest *moduleManifest) (*robot.Resta modID := args.ID // todo: use MutuallyExclusiveFlags for this when urfave/cli 3.x is stable if (len(modName) > 0) && (len(modID) > 0) { - return nil, fmt.Errorf("provide at most one of --%s and --%s", generalFlagName, moduleBuildFlagBuildID) + return nil, fmt.Errorf("provide at most one of --%s and --%s", generalFlagName, moduleFlagID) } request := &robot.RestartModuleRequest{} //nolint:gocritic @@ -668,7 +666,7 @@ func resolveTargetModule(c *cli.Context, manifest *moduleManifest) (*robot.Resta // TODO(APP-4019): remove localize call request.ModuleName = localizeModuleID(manifest.ModuleID) } else { - return nil, fmt.Errorf("if there is no meta.json, provide one of --%s or --%s", generalFlagName, moduleBuildFlagBuildID) + return nil, fmt.Errorf("if there is no meta.json, provide one of --%s or --%s", generalFlagName, moduleFlagID) } return request, nil } diff --git a/cli/module_registry.go b/cli/module_registry.go index dba0eb54eda..c2cd8d9d534 100644 --- a/cli/module_registry.go +++ b/cli/module_registry.go @@ -260,7 +260,7 @@ type uploadModuleArgs struct { Name string Version string Platform string - Tags string + Tags []string Force bool } @@ -353,11 +353,7 @@ func UploadModuleAction(c *cli.Context, args uploadModuleArgs) error { } } - var constraintsList []string - if constraints != "" { - constraintsList = strings.Split(constraints, ",") - } - response, err := client.uploadModuleFile(moduleID, versionArg, platformArg, constraintsList, tarballPath) + response, err := client.uploadModuleFile(moduleID, versionArg, platformArg, constraints, tarballPath) if err != nil { return err } From 575e412c5b274d159887766c41ab587e1700d11b Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 9 Jan 2025 13:41:17 -0500 Subject: [PATCH 18/38] standardize package subcommands --- cli/app.go | 56 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/cli/app.go b/cli/app.go index 0e4919cf739..deb9802f474 100644 --- a/cli/app.go +++ b/cli/app.go @@ -1568,11 +1568,11 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: mlTrainingFlagFramework, - Usage: "framework of the ML training script to upload, can be: [" + strings.Join(modelFrameworks, ", ") + "]", + Usage: fmt.Sprintf("framework of the ML training script to upload, can be: [%s]", strings.Join(modelFrameworks, ", ")), }, &cli.StringFlag{ Name: trainFlagModelType, - Usage: "task type of the ML training script to upload, can be: [" + strings.Join(modelTypes, ", ") + "]", + Usage: fmt.Sprintf("task type of the ML training script to upload, can be: [%s]", strings.Join(modelTypes, ", ")), }, &cli.StringSliceFlag{ Name: mlTrainingFlagArgs, @@ -2373,7 +2373,8 @@ Example: Name: "link-repo", Usage: "link a GitHub repository to your module", UsageText: createUsageText("module build link-repo", nil, true, false), - Description: `This command connects a Viam module to a GitHub repository so that repo actions can trigger builds and releases of your module. + Description: ` +This command connects a Viam module to a GitHub repository so that repo actions can trigger builds and releases of your module. This won't work unless you have an existing installation of our GitHub app on your GitHub org. (Details to follow).`, // TODO(APP-3604): unhide when this is shipped externally @@ -2416,8 +2417,8 @@ This won't work unless you have an existing installation of our GitHub app on yo viam module reload --local`, Flags: []cli.Flag{ &cli.StringFlag{ - Name: generalFlagPartID, - Usage: "part ID of machine. get from 'Live/Offline' dropdown in the web app", + Name: generalFlagPartID, + Usage: "part ID of machine. get from 'Live/Offline' dropdown in the web app", DefaultText: "/etc/viam.json", }, &cli.StringFlag{ @@ -2464,8 +2465,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Value: ".", }, &cli.StringFlag{ - Name: moduleFlagID, - Usage: "module ID as org-id:name or namespace:name", + Name: moduleFlagID, + Usage: "module ID as org-id:name or namespace:name", DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ @@ -2474,8 +2475,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Value: "latest", }, &cli.StringFlag{ - Name: moduleFlagPlatform, - Usage: "platform like 'linux/amd64'", + Name: moduleFlagPlatform, + Usage: "platform like 'linux/amd64'", DefaultText: "platform of the CLI binary", }, }, @@ -2486,13 +2487,13 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "packages", Usage: "work with packages", + UsageText: createUsageText("packages", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "export", - Usage: "download a package from Viam cloud", - UsageText: createUsageText("packages export", - []string{packageFlagType}, false, false), + Name: "export", + Usage: "download a package from Viam cloud", + UsageText: createUsageText("packages export", []string{packageFlagType}, false, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagDestination, @@ -2500,12 +2501,14 @@ This won't work unless you have an existing installation of our GitHub app on yo Value: ".", }, &cli.StringFlag{ - Name: generalFlagOrgID, - Usage: "organization ID or namespace of the requested package. if missing, will try to read from meta.json", + Name: generalFlagOrgID, + Usage: "organization ID or namespace of the requested package", + DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ - Name: generalFlagName, - Usage: "name of the requested package. if missing, will try to read from meta.json", + Name: generalFlagName, + Usage: "name of the requested package", + DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ Name: packageFlagVersion, @@ -2515,7 +2518,7 @@ This won't work unless you have an existing installation of our GitHub app on yo &cli.StringFlag{ Name: packageFlagType, Required: true, - Usage: "type of the requested package, can be: " + strings.Join(packageTypes, ", "), + Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), }, }, Action: createCommandWithT[packageExportArgs](PackageExportAction), @@ -2524,10 +2527,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Name: "upload", Usage: "upload a package to Viam cloud", UsageText: createUsageText("packages upload", - []string{ - packageFlagPath, generalFlagOrgID, generalFlagName, - packageFlagVersion, packageFlagType, - }, false, false), + []string{packageFlagPath, generalFlagOrgID, generalFlagName, packageFlagVersion, packageFlagType}, + false, false), Flags: []cli.Flag{ &cli.PathFlag{ Name: packageFlagPath, @@ -2552,13 +2553,14 @@ This won't work unless you have an existing installation of our GitHub app on yo &cli.StringFlag{ Name: packageFlagType, Required: true, - Usage: "type of the requested package, can be: " + strings.Join(packageTypes, ", "), + Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), }, &cli.StringFlag{ - Name: packageFlagFramework, - Required: false, - Usage: "framework for an ml_model being uploaded, can be: " + - strings.Join(modelFrameworks, ", ") + ", Required if packages if of type `ml_model`", + Name: packageFlagFramework, + Usage: fmt.Sprintf( + "framework for an ml_model being uploaded, can be: [%s]. Required if packages is of type 'ml_model'", + strings.Join(modelFrameworks, ", "), + ), }, }, Action: createCommandWithT[packageUploadArgs](PackageUploadAction), From 1d3ad89dfca5297c51b21744e67f1f5640f68dc9 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 13:50:58 -0500 Subject: [PATCH 19/38] standardize training script subcommands --- cli/app.go | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/cli/app.go b/cli/app.go index deb9802f474..81f2ff295ce 100644 --- a/cli/app.go +++ b/cli/app.go @@ -2570,12 +2570,13 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "training-script", Usage: "manage training scripts for custom ML training", + UsageText: createUsageText("training-script", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "upload", Usage: "upload ML training scripts for custom ML training", - UsageText: createUsageText("training-script upload", []string{mlTrainingFlagPath, mlTrainingFlagName}, true, false), + UsageText: createUsageText("training-script upload", []string{generalFlagOrgID, mlTrainingFlagPath, mlTrainingFlagName}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: mlTrainingFlagPath, @@ -2593,32 +2594,26 @@ This won't work unless you have an existing installation of our GitHub app on yo Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagVersion, - Usage: "version of the ML training script to upload", - Required: false, + Name: mlTrainingFlagVersion, + Usage: "version of the ML training script to upload", }, &cli.StringFlag{ - Name: mlTrainingFlagFramework, - Usage: "framework of the ML training script to upload, can be: " + strings.Join(modelFrameworks, ", "), - Required: false, + Name: mlTrainingFlagFramework, + Usage: fmt.Sprintf("framework of the ML training script to upload, can be: [%s]", strings.Join(modelFrameworks, ", ")), }, &cli.StringFlag{ - Name: mlTrainingFlagType, - Usage: "task type of the ML training script to upload, can be: " + strings.Join(modelTypes, ", "), - Required: false, + Name: mlTrainingFlagType, + Usage: fmt.Sprintf("task type of the ML training script to upload, can be: [%s]", strings.Join(modelTypes, ", ")), }, &cli.BoolFlag{ - Name: mlTrainingFlagDraft, - Usage: "indicate draft mode, drafts will not be viewable in the registry", - Required: false, + Name: mlTrainingFlagDraft, + Usage: "indicate draft mode, drafts will not be viewable in the registry", }, &cli.StringFlag{ - Name: mlTrainingFlagURL, - Usage: "url of Github repository associated with the training scripts", - Required: false, + Name: mlTrainingFlagURL, + Usage: "url of Github repository associated with the training scripts", }, }, - // Upload action Action: createCommandWithT[mlTrainingUploadArgs](MLTrainingUploadAction), }, { @@ -2644,14 +2639,12 @@ This won't work unless you have an existing installation of our GitHub app on yo Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagDescription, - Usage: "description of the ML training script", - Required: false, + Name: mlTrainingFlagDescription, + Usage: "description of the ML training script", }, &cli.StringFlag{ - Name: mlTrainingFlagURL, - Usage: "url of Github repository associated with the training scripts", - Required: false, + Name: mlTrainingFlagURL, + Usage: "url of Github repository associated with the training scripts", }, }, Action: createCommandWithT[mlTrainingUpdateArgs](MLTrainingUpdateAction), From 035c9dad19c6ec711c3ab9df49f66b4620bbadcf Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 14:41:19 -0500 Subject: [PATCH 20/38] standardize rest of commands --- cli/app.go | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/cli/app.go b/cli/app.go index 81f2ff295ce..aa0492328fb 100644 --- a/cli/app.go +++ b/cli/app.go @@ -2654,16 +2654,16 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "auth-app", Usage: "manage third party auth applications", + UsageText: createUsageText("auth-app", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { Name: "register", Usage: "register a third party auth application", - UsageText: createUsageText("auth-app register", []string{ - generalFlagOrgID, - authApplicationFlagName, authApplicationFlagOriginURIs, authApplicationFlagRedirectURIs, - authApplicationFlagLogoutURI, - }, false, false), + UsageText: createUsageText("auth-app register", + []string{ + generalFlagOrgID, authApplicationFlagName, authApplicationFlagOriginURIs, authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, + }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2696,11 +2696,9 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "update", Usage: "update a third party auth application", - UsageText: createUsageText("auth-app update", []string{ - generalFlagOrgID, - authApplicationFlagApplicationID, authApplicationFlagName, authApplicationFlagOriginURIs, - authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, - }, false, false), + UsageText: createUsageText( + "auth-app update", []string{generalFlagOrgID, authApplicationFlagApplicationID, authApplicationFlagName}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2718,19 +2716,16 @@ This won't work unless you have an existing installation of our GitHub app on yo Required: true, }, &cli.StringSliceFlag{ - Name: authApplicationFlagOriginURIs, - Usage: "updated origin uris for the auth application", - Required: false, + Name: authApplicationFlagOriginURIs, + Usage: "updated origin uris for the auth application", }, &cli.StringSliceFlag{ - Name: authApplicationFlagRedirectURIs, - Usage: "updated redirect uris for the auth application", - Required: false, + Name: authApplicationFlagRedirectURIs, + Usage: "updated redirect uris for the auth application", }, &cli.StringFlag{ - Name: authApplicationFlagLogoutURI, - Usage: "updated logout uri for the auth application", - Required: false, + Name: authApplicationFlagLogoutURI, + Usage: "updated logout uri for the auth application", }, }, Action: createCommandWithT[updateAuthApplicationArgs](UpdateAuthApplicationAction), @@ -2738,10 +2733,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "get", Usage: "get configuration for a third party auth application", - UsageText: createUsageText("auth-app get", []string{ - generalFlagOrgID, - authApplicationFlagApplicationID, - }, false, false), + UsageText: createUsageText("auth-app get", []string{generalFlagOrgID, authApplicationFlagApplicationID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -2761,6 +2753,7 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "version", Usage: "print version info for this program", + UsageText: createUsageText("version", nil, false, false), Action: createCommandWithT[emptyArgs](VersionAction), }, }, From 7b59c4297868d14a1117be47c6ce61278717ab78 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 14:42:16 -0500 Subject: [PATCH 21/38] make lint --- cli/app.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cli/app.go b/cli/app.go index aa0492328fb..e83e76becdf 100644 --- a/cli/app.go +++ b/cli/app.go @@ -2662,7 +2662,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Usage: "register a third party auth application", UsageText: createUsageText("auth-app register", []string{ - generalFlagOrgID, authApplicationFlagName, authApplicationFlagOriginURIs, authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, + generalFlagOrgID, authApplicationFlagName, authApplicationFlagOriginURIs, + authApplicationFlagRedirectURIs, authApplicationFlagLogoutURI, }, false, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -2731,8 +2732,8 @@ This won't work unless you have an existing installation of our GitHub app on yo Action: createCommandWithT[updateAuthApplicationArgs](UpdateAuthApplicationAction), }, { - Name: "get", - Usage: "get configuration for a third party auth application", + Name: "get", + Usage: "get configuration for a third party auth application", UsageText: createUsageText("auth-app get", []string{generalFlagOrgID, authApplicationFlagApplicationID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -2751,10 +2752,10 @@ This won't work unless you have an existing installation of our GitHub app on yo }, }, { - Name: "version", - Usage: "print version info for this program", + Name: "version", + Usage: "print version info for this program", UsageText: createUsageText("version", nil, false, false), - Action: createCommandWithT[emptyArgs](VersionAction), + Action: createCommandWithT[emptyArgs](VersionAction), }, }, } From c65cfc4be1b89f182cdfd5e9cdf1834c546c7a04 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 14:50:18 -0500 Subject: [PATCH 22/38] fix new command --- cli/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/app.go b/cli/app.go index 61fdf820674..485b277d6f2 100644 --- a/cli/app.go +++ b/cli/app.go @@ -508,7 +508,7 @@ var app = &cli.App{ { Name: "disable", Usage: "disable auth-service for OAuth applications", - UsageText: createUsageText("disable", []string{generalFlagOrgID}, false, false), + UsageText: createUsageText("organizations auth-service disable", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, From a488accb201e2d5524d3ee08554a7cb0ba5cd0dd Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 15:26:56 -0500 Subject: [PATCH 23/38] fix new commands --- cli/app.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cli/app.go b/cli/app.go index 485b277d6f2..fb7e8dde17e 100644 --- a/cli/app.go +++ b/cli/app.go @@ -550,7 +550,7 @@ var app = &cli.App{ Name: "list", Usage: "list oauth applications for an organization", UsageText: createUsageText( - "organizations auth-service oauth-app list", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false, + "organizations auth-service oauth-app list", []string{generalFlagOrgID}, false, false, ), Flags: []cli.Flag{ &cli.StringFlag{ @@ -562,8 +562,11 @@ var app = &cli.App{ Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction), }, { - Name: "read", - Usage: "read the OAuth configuration details", + Name: "read", + Usage: "read the OAuth configuration details", + UsageText: createUsageText( + "organizations auth-service oauth-app read", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false, + ), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, @@ -644,11 +647,17 @@ var app = &cli.App{ { Name: "create", Usage: "create an OAuth application", + UsageText: createUsageText("organizations auth-serice oauth-app create", + []string{ + generalFlagOrgID, oauthAppFlagClientAuthentication, oauthAppFlagURLValidation, oauthAppFlagPKCE, + oauthAppFlagRedirectURIs, oauthAppFlagLogoutURI, oauthAppFlagEnabledGrants, + }, + true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, - Required: true, Usage: "organization ID that is tied to the OAuth application", + Required: true, }, &cli.StringFlag{ Name: oauthAppFlagClientName, @@ -659,7 +668,6 @@ var app = &cli.App{ Usage: "client authentication policy for the OAuth application. can be one of " + formatAcceptedValues(string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE)), - Value: unspecified, Required: true, }, &cli.StringFlag{ @@ -667,7 +675,6 @@ var app = &cli.App{ Usage: "url validation for the OAuth application. can be one of " + formatAcceptedValues(string(URLValidationUnspecified), string(URLValidationExactMatch), string(URLValidationAllowWildcards)), - Value: unspecified, Required: true, }, &cli.StringFlag{ @@ -675,7 +682,6 @@ var app = &cli.App{ Usage: "pkce for the OAuth application. can be one of " + formatAcceptedValues(string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), string(PKCENotRequiredWhenUsingClientAuthentication)), - Value: unspecified, Required: true, }, &cli.StringSliceFlag{ From 2099e427afaf6d7bb65d22392d350dac7c8fb728 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 15:27:15 -0500 Subject: [PATCH 24/38] make lint --- cli/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/app.go b/cli/app.go index fb7e8dde17e..99f069ef313 100644 --- a/cli/app.go +++ b/cli/app.go @@ -562,8 +562,8 @@ var app = &cli.App{ Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction), }, { - Name: "read", - Usage: "read the OAuth configuration details", + Name: "read", + Usage: "read the OAuth configuration details", UsageText: createUsageText( "organizations auth-service oauth-app read", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false, ), From ffb80c127cb9efb343b190329bf57d242d74a0d1 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 15:28:50 -0500 Subject: [PATCH 25/38] nit --- cli/app.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/app.go b/cli/app.go index 99f069ef313..a7af051697c 100644 --- a/cli/app.go +++ b/cli/app.go @@ -549,9 +549,7 @@ var app = &cli.App{ { Name: "list", Usage: "list oauth applications for an organization", - UsageText: createUsageText( - "organizations auth-service oauth-app list", []string{generalFlagOrgID}, false, false, - ), + UsageText: createUsageText("organizations auth-service oauth-app list", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrgID, From 0a7f5400b253095eecd2902d3fd5bf76d6b85e8b Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 15:37:58 -0500 Subject: [PATCH 26/38] nits --- cli/app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/app.go b/cli/app.go index a7af051697c..68229637cd8 100644 --- a/cli/app.go +++ b/cli/app.go @@ -547,8 +547,8 @@ var app = &cli.App{ Action: createCommandWithT[deleteOAuthAppArgs](DeleteOAuthAppAction), }, { - Name: "list", - Usage: "list oauth applications for an organization", + Name: "list", + Usage: "list oauth applications for an organization", UsageText: createUsageText("organizations auth-service oauth-app list", []string{generalFlagOrgID}, false, false), Flags: []cli.Flag{ &cli.StringFlag{ @@ -2731,7 +2731,7 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: mlTrainingFlagVisibility, - Usage: "visibility of the registry item, can be: `public` or `private`", + Usage: "visibility of the registry item, can be: ['public', 'private']", Required: true, }, &cli.StringFlag{ From 2754e3ef6eceaa877261cc335736cdad31b63fe1 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 16:10:14 -0500 Subject: [PATCH 27/38] deal with other argument-using commands --- cli/app.go | 14 ++++++++++---- cli/client.go | 2 -- cli/module_registry.go | 10 ++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cli/app.go b/cli/app.go index 68229637cd8..471c5b55a3e 100644 --- a/cli/app.go +++ b/cli/app.go @@ -74,6 +74,7 @@ const ( moduleFlagRegister = "register" moduleFlagTags = "tags" moduleFlagDryRun = "dry-run" + moduleFlagUpload = "upload" moduleBuildFlagPath = "module" moduleBuildFlagRef = "ref" @@ -2277,18 +2278,18 @@ After creation, use 'viam module update' to push your new module to app.viam.com Usage: "upload a new version of your module", Description: `Upload an archive containing your module's file(s) for a specified platform Example uploading a single file: -viam module upload --version "0.1.0" --platform "linux/amd64" ./bin/my-module +viam module upload --version "0.1.0" --platform "linux/amd64" --upload "./bin/my-module" (this example requires the entrypoint in the meta.json to be "./bin/my-module") Example uploading a whole directory: -viam module upload --version "0.1.0" --platform "linux/amd64" ./bin +viam module upload --version "0.1.0" --platform "linux/amd64" --upload "./bin" (this example requires the entrypoint in the meta.json to be inside the bin directory like "./bin/[your path here]") Example uploading a custom tarball of your module: tar -czf packaged-module.tar.gz ./src requirements.txt run.sh -viam module upload --version "0.1.0" --platform "linux/amd64" packaged-module.tar.gz +viam module upload --version "0.1.0" --platform "linux/amd64" --upload "packaged-module.tar.gz" `, - UsageText: createUsageText("module upload", []string{moduleFlagVersion, moduleFlagPlatform}, true, false, ""), + UsageText: createUsageText("module upload", []string{moduleFlagVersion, moduleFlagPlatform, moduleFlagUpload}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2340,6 +2341,11 @@ viam module upload --version "0.1.0" --platform "linux/amd64" packaged-module.ta Name: moduleFlagForce, Usage: "skip validation (may result in non-functional versions)", }, + &cli.StringFlag{ + Name: moduleFlagUpload, + Usage: "the path to the upload", + Required: false, // should be true, but set to false to allow for backwards compatibility + }, }, Action: createCommandWithT[uploadModuleArgs](UploadModuleAction), }, diff --git a/cli/client.go b/cli/client.go index 23c58332c7c..b9255d76bba 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1163,8 +1163,6 @@ func MachinesPartCopyFilesAction(c *cli.Context, args machinesPartCopyFilesArgs) } func machinesPartCopyFilesAction(c *cli.Context, client *viamClient, flagArgs machinesPartCopyFilesArgs) error { - // TODO(RSDK-9288) - this is brittle and inconsistent with how most data is passed. - // Move this to being a flag (but make sure existing workflows still work!) args := c.Args().Slice() if len(args) == 0 { return errNoFiles diff --git a/cli/module_registry.go b/cli/module_registry.go index c2cd8d9d534..e99e8bbad3a 100644 --- a/cli/module_registry.go +++ b/cli/module_registry.go @@ -262,6 +262,7 @@ type uploadModuleArgs struct { Platform string Tags []string Force bool + Upload string } // UploadModuleAction is the corresponding action for 'module upload'. @@ -274,12 +275,9 @@ func UploadModuleAction(c *cli.Context, args uploadModuleArgs) error { platformArg := args.Platform forceUploadArg := args.Force constraints := args.Tags - // TODO(RSDK-9288) - this is brittle and inconsistent with how most data is passed. - // Move this to being a flag (but make sure existing workflows still work!) - moduleUploadPath := c.Args().First() - if c.Args().Len() > 1 { - return errors.New("too many arguments passed to upload command. " + - "Make sure to specify flag and optional arguments before the required positional package argument") + moduleUploadPath := args.Upload + if moduleUploadPath == "" { + moduleUploadPath = c.Args().First() } if moduleUploadPath == "" { return errors.New("nothing to upload -- please provide a path to your module. Use --help for more information") From 4e621bb2d854f2fc7f2c0691935b0a497d335578 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 16:31:46 -0500 Subject: [PATCH 28/38] consolidate flags --- cli/app.go | 163 ++++++++++++++++++-------------------- cli/client.go | 4 +- cli/client_test.go | 4 +- cli/module_build_test.go | 6 +- cli/module_reload_test.go | 4 +- 5 files changed, 84 insertions(+), 97 deletions(-) diff --git a/cli/app.go b/cli/app.go index 471c5b55a3e..1c9b0f690a5 100644 --- a/cli/app.go +++ b/cli/app.go @@ -27,7 +27,6 @@ const ( logsFlagOutputFile = "output" logsFlagErrors = "errors" logsFlagTail = "tail" - logsFlagCount = "count" runFlagData = "data" runFlagStream = "stream" @@ -36,7 +35,7 @@ const ( loginFlagKeyID = "key-id" loginFlagKey = "key" - // Flags shared by api-key, module, ml-training, package, and data subcommands. + // Flags shared by logs, api-key, module, ml-training, package, and data subcommands. generalFlagOrganization = "organization" generalFlagAliasOrg = "org" generalFlagAliasOrgName = "org-name" @@ -45,20 +44,26 @@ const ( generalFlagAliasLocationName = "location-name" generalFlagLocationID = "location-id" generalFlagMachine = "machine" - generalFlagAliasMachineName = "machine-name" + generalFlagMachineName = "machine-name" generalFlagMachineID = "machine-id" generalFlagAliasRobot = "robot" generalFlagAliasRobotID = "robot-id" generalFlagPart = "part" - generalFlagAliasPartName = "part-name" + generalFlagPartName = "part-name" generalFlagPartID = "part-id" generalFlagName = "name" generalFlagMethod = "method" + generalFlagDestination = "destination" + generalFlagVersion = "version" + generalFlagCount = "count" + generalFlagPath = "path" + generalFlagType = "type" + generalFlagResourceSubtype = "resource-subtype" + generalFlagTags = "tags" moduleFlagLanguage = "language" moduleFlagPublicNamespace = "public-namespace" moduleFlagPath = "module" - moduleFlagVersion = "version" moduleFlagPlatform = "platform" moduleFlagForce = "force" moduleFlagBinary = "binary" @@ -68,19 +73,13 @@ const ( moduleFlagID = "id" moduleFlagIsPublic = "public" moduleFlagResourceType = "resource-type" - moduleFlagResourceSubtype = "resource-subtype" moduleFlagModelName = "model-name" moduleFlagEnableCloud = "enable-cloud" moduleFlagRegister = "register" - moduleFlagTags = "tags" moduleFlagDryRun = "dry-run" moduleFlagUpload = "upload" - moduleBuildFlagPath = "module" moduleBuildFlagRef = "ref" - moduleBuildFlagCount = "count" - moduleBuildFlagVersion = "version" - moduleBuildFlagPlatform = "platform" moduleBuildFlagWait = "wait" moduleBuildFlagToken = "token" moduleBuildFlagWorkdir = "workdir" @@ -91,44 +90,32 @@ const ( moduleBuildFlagOAuthLink = "oauth-link" moduleBuildFlagRepo = "repo" - mlTrainingFlagPath = "path" mlTrainingFlagName = "script-name" - mlTrainingFlagVersion = "version" mlTrainingFlagFramework = "framework" - mlTrainingFlagType = "type" mlTrainingFlagDraft = "draft" mlTrainingFlagVisibility = "visibility" mlTrainingFlagDescription = "description" mlTrainingFlagURL = "url" mlTrainingFlagArgs = "args" - dataFlagDestination = "destination" dataFlagDataType = "data-type" dataFlagOrgIDs = "org-ids" dataFlagLocationIDs = "location-ids" - dataFlagMachineName = "machine-name" dataFlagAliasRobotName = "robot-name" - dataFlagPartName = "part-name" dataFlagComponentType = "component-type" - dataFlagResourceSubtype = "resource-subtype" dataFlagComponentName = "component-name" dataFlagResourceName = "resource-name" dataFlagMimeTypes = "mime-types" dataFlagStart = "start" dataFlagEnd = "end" dataFlagParallelDownloads = "parallel" - dataFlagTags = "tags" dataFlagBboxLabels = "bbox-labels" dataFlagDeleteTabularDataOlderThanDays = "delete-older-than-days" dataFlagDatabasePassword = "password" dataFlagFilterTags = "filter-tags" dataFlagTimeout = "timeout" - packageFlagVersion = "version" - packageFlagType = "type" - packageFlagDestination = "destination" - packageFlagPath = "path" - packageFlagFramework = "model-framework" + packageFlagFramework = "model-framework" packageMetadataFlagFramework = "model_framework" @@ -185,13 +172,13 @@ var commonFilterFlags = []cli.Flag{ }, &AliasStringFlag{ cli.StringFlag{ - Name: dataFlagMachineName, + Name: generalFlagMachineName, Aliases: []string{dataFlagAliasRobotName}, Usage: "machine name filter", }, }, &cli.StringFlag{ - Name: dataFlagPartName, + Name: generalFlagPartName, Usage: "part name filter", }, &cli.StringFlag{ @@ -226,7 +213,7 @@ var commonFilterFlags = []cli.Flag{ var dataTagByIDsFlags = []cli.Flag{ &cli.StringSliceFlag{ - Name: dataFlagTags, + Name: generalFlagTags, Usage: "comma separated tags to add/remove to the data", Required: true, }, @@ -249,7 +236,7 @@ var dataTagByIDsFlags = []cli.Flag{ var dataTagByFilterFlags = append([]cli.Flag{ &cli.StringSliceFlag{ - Name: dataFlagTags, + Name: generalFlagTags, Required: true, Usage: "comma separated tags to add/remove to the data", }, @@ -1038,10 +1025,10 @@ var app = &cli.App{ { Name: "binary", Usage: "download binary data", - UsageText: createUsageText("data export binary", []string{dataFlagDestination}, true, false), + UsageText: createUsageText("data export binary", []string{generalFlagDestination}, true, false), Flags: append([]cli.Flag{ &cli.PathFlag{ - Name: dataFlagDestination, + Name: generalFlagDestination, Required: true, Usage: "output directory for downloaded data", }, @@ -1056,7 +1043,7 @@ var app = &cli.App{ Value: 30, }, &cli.StringSliceFlag{ - Name: dataFlagTags, + Name: generalFlagTags, Usage: "tags filter. accepts tagged for all tagged data, untagged for all untagged data, or a list of tags", }, }, commonFilterFlags...), @@ -1066,15 +1053,15 @@ var app = &cli.App{ Name: "tabular", Usage: "download tabular data", UsageText: createUsageText("data export tabular", []string{ - dataFlagDestination, + generalFlagDestination, generalFlagPartID, dataFlagResourceName, - dataFlagResourceSubtype, + generalFlagResourceSubtype, generalFlagMethod, }, true, false), Flags: []cli.Flag{ &cli.PathFlag{ - Name: dataFlagDestination, + Name: generalFlagDestination, Required: true, Usage: "output directory for downloaded data", }, @@ -1089,7 +1076,7 @@ var app = &cli.App{ Usage: "resource name (sometimes called 'component name')", }, &cli.StringFlag{ - Name: dataFlagResourceSubtype, + Name: generalFlagResourceSubtype, Required: true, Usage: "resource subtype (sometimes called 'component type')", }, @@ -1154,13 +1141,13 @@ var app = &cli.App{ }, &AliasStringFlag{ cli.StringFlag{ - Name: dataFlagMachineName, + Name: generalFlagMachineName, Aliases: []string{dataFlagAliasRobotName}, Usage: "machine name filter", }, }, &cli.StringFlag{ - Name: dataFlagPartName, + Name: generalFlagPartName, Usage: "part name filter", }, &cli.StringFlag{ @@ -1263,7 +1250,7 @@ var app = &cli.App{ Name: "add", Usage: "adds tags to binary data by file ids for a given org and location", UsageText: createUsageText( - "data tag ids add", []string{dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + "data tag ids add", []string{generalFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, ), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), @@ -1272,7 +1259,7 @@ var app = &cli.App{ Name: "remove", Usage: "removes tags from binary data by file ids for a given org and location", UsageText: createUsageText( - "data tag ids remove", []string{dataFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, + "data tag ids remove", []string{generalFlagTags, generalFlagOrgID, dataFlagLocationID, dataFlagFileIDs}, false, false, ), Flags: dataTagByIDsFlags, Action: createCommandWithT[dataTagByIDsArgs](DataTagActionByIds), @@ -1288,14 +1275,14 @@ var app = &cli.App{ { Name: "add", Usage: "adds tags to binary data by filter", - UsageText: createUsageText("data tag filter add", []string{dataFlagTags}, false, false), + UsageText: createUsageText("data tag filter add", []string{generalFlagTags}, false, false), Flags: dataTagByFilterFlags, Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, { Name: "remove", Usage: "removes tags from binary data by filter", - UsageText: createUsageText("data tag filter remove", []string{dataFlagTags}, false, false), + UsageText: createUsageText("data tag filter remove", []string{generalFlagTags}, false, false), Flags: dataTagByFilterFlags, Action: createCommandWithT[dataTagByFilterArgs](DataTagActionByFilter), }, @@ -1383,10 +1370,10 @@ var app = &cli.App{ Name: "export", Usage: "download data from a dataset", UsageText: createUsageText("dataset export", - []string{dataFlagDestination, datasetFlagDatasetID}, true, false), + []string{generalFlagDestination, datasetFlagDatasetID}, true, false), Flags: []cli.Flag{ &cli.PathFlag{ - Name: dataFlagDestination, + Name: generalFlagDestination, Required: true, Usage: "output directory for downloaded data", }, @@ -1465,7 +1452,7 @@ var app = &cli.App{ Required: true, }, &cli.StringSliceFlag{ - Name: dataFlagTags, + Name: generalFlagTags, Usage: "tags filter. " + "accepts tagged for all tagged data, untagged for all untagged data, or a list of tags for all data matching any of the tags", }, @@ -1572,7 +1559,7 @@ var app = &cli.App{ Name: "from-registry", Usage: "submits custom training job with an existing training script in the registry on data in Viam cloud", UsageText: createUsageText("train submit custom from-registry", - []string{datasetFlagDatasetID, generalFlagOrgID, trainFlagModelName, mlTrainingFlagName, mlTrainingFlagVersion}, + []string{datasetFlagDatasetID, generalFlagOrgID, trainFlagModelName, mlTrainingFlagName, generalFlagVersion}, true, false, ), Flags: []cli.Flag{ @@ -1602,7 +1589,7 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagVersion, + Name: generalFlagVersion, Usage: "version of the ML training script to use for training.", Required: true, }, @@ -1617,7 +1604,7 @@ var app = &cli.App{ Name: "with-upload", Usage: "submits custom training job with an upload training script on data in Viam cloud", UsageText: createUsageText("train submit custom with-upload", - []string{generalFlagOrgID, datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, mlTrainingFlagPath, mlTrainingFlagName}, + []string{generalFlagOrgID, datasetFlagDatasetID, trainFlagModelOrgID, trainFlagModelName, generalFlagPath, mlTrainingFlagName}, true, false, ), Flags: []cli.Flag{ @@ -1640,7 +1627,7 @@ var app = &cli.App{ Usage: "url of Github repository associated with the training scripts", }, &cli.StringFlag{ - Name: mlTrainingFlagPath, + Name: generalFlagPath, Usage: "path to ML training scripts for upload", Required: true, }, @@ -1660,7 +1647,7 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagVersion, + Name: generalFlagVersion, Usage: "version of the ML training script to upload. defaults to current timestamp if unspecified.", }, &cli.StringFlag{ @@ -1819,7 +1806,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, @@ -1846,7 +1833,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, @@ -1863,7 +1850,7 @@ var app = &cli.App{ Usage: "show only errors", }, &cli.IntFlag{ - Name: logsFlagCount, + Name: generalFlagCount, Usage: fmt.Sprintf("number of logs to fetch (max %v)", maxNumLogs), DefaultText: fmt.Sprintf("%v", defaultNumLogs), }, @@ -1895,14 +1882,14 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -1928,14 +1915,14 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -1949,7 +1936,7 @@ var app = &cli.App{ Usage: "follow logs", }, &cli.IntFlag{ - Name: logsFlagCount, + Name: generalFlagCount, Usage: fmt.Sprintf("number of logs to fetch (max %v)", maxNumLogs), DefaultText: fmt.Sprintf("%v", defaultNumLogs), }, @@ -1975,14 +1962,14 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -2015,14 +2002,14 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -2063,14 +2050,14 @@ Organization and location are required flags if the machine/part name are not un &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -2122,14 +2109,14 @@ Copy multiple files from the machine to a local destination with recursion and k &AliasStringFlag{ cli.StringFlag{ Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagAliasMachineName}, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, Required: true, }, }, &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -2213,7 +2200,7 @@ After creation, use 'viam module update' to push your new module to app.viam.com Usage: "namespace or organization ID of module", }, &cli.StringFlag{ - Name: moduleFlagResourceSubtype, + Name: generalFlagResourceSubtype, Usage: "resource subtype to use in module", }, &cli.StringFlag{ @@ -2289,7 +2276,7 @@ Example uploading a custom tarball of your module: tar -czf packaged-module.tar.gz ./src requirements.txt run.sh viam module upload --version "0.1.0" --platform "linux/amd64" --upload "packaged-module.tar.gz" `, - UsageText: createUsageText("module upload", []string{moduleFlagVersion, moduleFlagPlatform, moduleFlagUpload}, true, false), + UsageText: createUsageText("module upload", []string{generalFlagVersion, moduleFlagPlatform, moduleFlagUpload}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ Name: moduleFlagPath, @@ -2310,7 +2297,7 @@ viam module upload --version "0.1.0" --platform "linux/amd64" --upload "packaged Usage: "name of the module (used if you don't have a meta.json)", }, &cli.StringFlag{ - Name: moduleFlagVersion, + Name: generalFlagVersion, Usage: "version of the module to upload (semver2.0) ex: \"0.1.0\"", Required: true, }, @@ -2331,7 +2318,7 @@ viam module upload --version "0.1.0" --platform "linux/amd64" --upload "packaged Required: true, }, &cli.StringSliceFlag{ - Name: moduleFlagTags, + Name: generalFlagTags, Usage: `extra fields for constraining the platforms to which this binary is deployed. Examples: distro:debian, distro:ubuntu, os_version:22.04, os_codename:jammy. For a machine to use an upload, all tags must be @@ -2386,16 +2373,16 @@ Example: { Name: "start", Usage: "start a remote build", - UsageText: createUsageText("module build start", []string{moduleBuildFlagVersion}, true, false), + UsageText: createUsageText("module build start", []string{generalFlagVersion}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ - Name: moduleBuildFlagPath, + Name: moduleFlagPath, Usage: "path to meta.json", Value: "./meta.json", TakesFile: true, }, &cli.StringFlag{ - Name: moduleBuildFlagVersion, + Name: generalFlagVersion, Usage: "version of the module to upload (semver2.0) ex: \"0.1.0\"", Required: true, }, @@ -2432,7 +2419,7 @@ Example: TakesFile: true, }, &cli.IntFlag{ - Name: moduleBuildFlagCount, + Name: generalFlagCount, Usage: "number of builds to list", Aliases: []string{"c"}, DefaultText: "all", @@ -2456,7 +2443,7 @@ Example: Required: true, }, &cli.StringFlag{ - Name: moduleBuildFlagPlatform, + Name: moduleFlagPlatform, Usage: "build platform to get the logs for. Ex: linux/arm64.", DefaultText: "all platforms", }, @@ -2562,7 +2549,7 @@ This won't work unless you have an existing installation of our GitHub app on yo UsageText: createUsageText("module download", []string{}, true, false), Flags: []cli.Flag{ &cli.PathFlag{ - Name: packageFlagDestination, + Name: generalFlagDestination, Usage: "output directory for downloaded package", Value: ".", }, @@ -2572,7 +2559,7 @@ This won't work unless you have an existing installation of our GitHub app on yo DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ - Name: packageFlagVersion, + Name: generalFlagVersion, Usage: "version of the requested package, can be `latest` to get the most recent version", Value: "latest", }, @@ -2595,10 +2582,10 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "export", Usage: "download a package from Viam cloud", - UsageText: createUsageText("packages export", []string{packageFlagType}, false, false), + UsageText: createUsageText("packages export", []string{generalFlagType}, false, false), Flags: []cli.Flag{ &cli.PathFlag{ - Name: packageFlagDestination, + Name: generalFlagDestination, Usage: "output directory for downloaded package", Value: ".", }, @@ -2613,12 +2600,12 @@ This won't work unless you have an existing installation of our GitHub app on yo DefaultText: "will try to read from meta.json", }, &cli.StringFlag{ - Name: packageFlagVersion, + Name: generalFlagVersion, Usage: "version of the requested package, can be `latest` to get the most recent version", Value: "latest", }, &cli.StringFlag{ - Name: packageFlagType, + Name: generalFlagType, Required: true, Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), }, @@ -2629,11 +2616,11 @@ This won't work unless you have an existing installation of our GitHub app on yo Name: "upload", Usage: "upload a package to Viam cloud", UsageText: createUsageText("packages upload", - []string{packageFlagPath, generalFlagOrgID, generalFlagName, packageFlagVersion, packageFlagType}, + []string{generalFlagPath, generalFlagOrgID, generalFlagName, generalFlagVersion, generalFlagType}, false, false), Flags: []cli.Flag{ &cli.PathFlag{ - Name: packageFlagPath, + Name: generalFlagPath, Required: true, Usage: "path to package for upload", }, @@ -2648,12 +2635,12 @@ This won't work unless you have an existing installation of our GitHub app on yo Usage: "name of the requested package", }, &cli.StringFlag{ - Name: packageFlagVersion, + Name: generalFlagVersion, Required: true, Usage: "version of the requested package, can be `latest` to get the most recent version", }, &cli.StringFlag{ - Name: packageFlagType, + Name: generalFlagType, Required: true, Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), }, @@ -2678,10 +2665,10 @@ This won't work unless you have an existing installation of our GitHub app on yo { Name: "upload", Usage: "upload ML training scripts for custom ML training", - UsageText: createUsageText("training-script upload", []string{generalFlagOrgID, mlTrainingFlagPath, mlTrainingFlagName}, true, false), + UsageText: createUsageText("training-script upload", []string{generalFlagOrgID, generalFlagPath, mlTrainingFlagName}, true, false), Flags: []cli.Flag{ &cli.StringFlag{ - Name: mlTrainingFlagPath, + Name: generalFlagPath, Usage: "path to ML training scripts for upload", Required: true, }, @@ -2696,7 +2683,7 @@ This won't work unless you have an existing installation of our GitHub app on yo Required: true, }, &cli.StringFlag{ - Name: mlTrainingFlagVersion, + Name: generalFlagVersion, Usage: "version of the ML training script to upload", }, &cli.StringFlag{ @@ -2704,7 +2691,7 @@ This won't work unless you have an existing installation of our GitHub app on yo Usage: fmt.Sprintf("framework of the ML training script to upload, can be: [%s]", strings.Join(modelFrameworks, ", ")), }, &cli.StringFlag{ - Name: mlTrainingFlagType, + Name: generalFlagType, Usage: fmt.Sprintf("task type of the ML training script to upload, can be: [%s]", strings.Join(modelTypes, ", ")), }, &cli.BoolFlag{ diff --git a/cli/client.go b/cli/client.go index b9255d76bba..6166954e71b 100644 --- a/cli/client.go +++ b/cli/client.go @@ -734,14 +734,14 @@ func RobotsStatusAction(c *cli.Context, args robotsStatusArgs) error { func getNumLogs(c *cli.Context, numLogs int) (int, error) { if numLogs < 0 { - warningf(c.App.ErrWriter, "Provided negative %q value. Defaulting to %d", logsFlagCount, defaultNumLogs) + warningf(c.App.ErrWriter, "Provided negative %q value. Defaulting to %d", generalFlagCount, defaultNumLogs) return defaultNumLogs, nil } if numLogs == 0 { return defaultNumLogs, nil } if numLogs > maxNumLogs { - return 0, errors.Errorf("provided too high of a %q value. Maximum is %d", logsFlagCount, maxNumLogs) + return 0, errors.Errorf("provided too high of a %q value. Maximum is %d", generalFlagCount, maxNumLogs) } return numLogs, nil } diff --git a/cli/client_test.go b/cli/client_test.go index 2e3838cb7b0..a0fbb02d535 100644 --- a/cli/client_test.go +++ b/cli/client_test.go @@ -105,7 +105,7 @@ func setup( if dataClient != nil { // these flags are only relevant when testing a dataClient - flags.String(dataFlagDestination, utils.ResolveFile(""), "") + flags.String(generalFlagDestination, utils.ResolveFile(""), "") } cCtx := cli.NewContext(NewApp(out, errOut), flags, nil) @@ -774,7 +774,7 @@ func TestGetRobotPartLogs(t *testing.T) { } }) t.Run("max count", func(t *testing.T) { - flags := map[string]any{logsFlagCount: maxNumLogs} + flags := map[string]any{generalFlagCount: maxNumLogs} cCtx, ac, out, errOut := setup(asc, nil, nil, nil, flags, "") test.That(t, ac.robotsPartLogsAction(cCtx, parseStructFromCtx[robotsPartLogsArgs](cCtx)), test.ShouldBeNil) diff --git a/cli/module_build_test.go b/cli/module_build_test.go index 4f28751a3e1..a7eeb58d7c0 100644 --- a/cli/module_build_test.go +++ b/cli/module_build_test.go @@ -56,7 +56,7 @@ func TestStartBuild(t *testing.T) { StartBuildFunc: func(ctx context.Context, in *v1.StartBuildRequest, opts ...grpc.CallOption) (*v1.StartBuildResponse, error) { return &v1.StartBuildResponse{BuildId: "xyz123"}, nil }, - }, nil, map[string]any{moduleBuildFlagPath: manifest, moduleBuildFlagVersion: "1.2.3"}, "token") + }, nil, map[string]any{moduleFlagPath: manifest, generalFlagVersion: "1.2.3"}, "token") err := ac.moduleBuildStartAction(cCtx, parseStructFromCtx[moduleBuildStartArgs](cCtx)) test.That(t, err, test.ShouldBeNil) test.That(t, out.messages, test.ShouldHaveLength, 1) @@ -79,7 +79,7 @@ func TestListBuild(t *testing.T) { }, }}, nil }, - }, nil, map[string]any{moduleBuildFlagPath: manifest}, "token") + }, nil, map[string]any{moduleFlagPath: manifest}, "token") err := ac.moduleBuildListAction(cCtx, parseStructFromCtx[moduleBuildListArgs](cCtx)) test.That(t, err, test.ShouldBeNil) joinedOutput := strings.Join(out.messages, "") @@ -195,7 +195,7 @@ func TestLocalBuild(t *testing.T) { // run the build local action cCtx, _, out, errOut := setup(&inject.AppServiceClient{}, nil, &inject.BuildServiceClient{}, - nil, map[string]any{moduleBuildFlagPath: manifestPath, moduleBuildFlagVersion: "1.2.3"}, "token") + nil, map[string]any{moduleFlagPath: manifestPath, generalFlagVersion: "1.2.3"}, "token") manifest, err := loadManifest(manifestPath) test.That(t, err, test.ShouldBeNil) err = moduleBuildLocalAction(cCtx, &manifest) diff --git a/cli/module_reload_test.go b/cli/module_reload_test.go index e111e677b5a..498152f27fa 100644 --- a/cli/module_reload_test.go +++ b/cli/module_reload_test.go @@ -22,7 +22,7 @@ func TestConfigureModule(t *testing.T) { StartBuildFunc: func(ctx context.Context, in *v1.StartBuildRequest, opts ...grpc.CallOption) (*v1.StartBuildResponse, error) { return &v1.StartBuildResponse{BuildId: "xyz123"}, nil }, - }, nil, map[string]any{moduleBuildFlagPath: manifestPath, moduleBuildFlagVersion: "1.2.3"}, "token") + }, nil, map[string]any{moduleFlagPath: manifestPath, generalFlagVersion: "1.2.3"}, "token") err := ac.moduleBuildStartAction(cCtx, parseStructFromCtx[moduleBuildStartArgs](cCtx)) test.That(t, err, test.ShouldBeNil) test.That(t, out.messages, test.ShouldHaveLength, 1) @@ -61,7 +61,7 @@ func TestFullReloadFlow(t *testing.T) { }, }, nil, &inject.BuildServiceClient{}, nil, map[string]any{ - moduleBuildFlagPath: manifestPath, generalFlagPartID: "part-123", + moduleFlagPath: manifestPath, generalFlagPartID: "part-123", moduleBuildFlagNoBuild: true, moduleFlagLocal: true, }, "token", From 05065fc9ccec7adcae860537a725672c78be1e52 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Fri, 10 Jan 2025 16:37:13 -0500 Subject: [PATCH 29/38] remove unnecessary flag --- cli/app.go | 2 -- cli/packages.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/app.go b/cli/app.go index 1c9b0f690a5..3a87382e949 100644 --- a/cli/app.go +++ b/cli/app.go @@ -117,8 +117,6 @@ const ( packageFlagFramework = "model-framework" - packageMetadataFlagFramework = "model_framework" - // TODO: APP-6993 remove these flags. authApplicationFlagName = "application-name" authApplicationFlagApplicationID = "application-id" diff --git a/cli/packages.go b/cli/packages.go index eb8fb708efe..c65ec812e64 100644 --- a/cli/packages.go +++ b/cli/packages.go @@ -207,7 +207,7 @@ func PackageUploadAction(c *cli.Context, args packageUploadArgs) error { args.Path, &structpb.Struct{ Fields: map[string]*structpb.Value{ - packageMetadataFlagFramework: { + "model_framework": { Kind: &structpb.Value_StringValue{ StringValue: args.ModelFramework, }, From 3d95348ab96260d49d852d340a69cda16438aea1 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Mon, 13 Jan 2025 12:14:14 -0500 Subject: [PATCH 30/38] basic cleanup --- cli/app.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/cli/app.go b/cli/app.go index 3a87382e949..6fe7e5de310 100644 --- a/cli/app.go +++ b/cli/app.go @@ -888,7 +888,7 @@ var app = &cli.App{ Name: "locations", Aliases: []string{"location"}, Usage: "work with locations", - UsageText: "viam locations [command options]", + UsageText: createUsageText("locations", nil, false, true), HideHelpCommand: true, Subcommands: []*cli.Command{ { @@ -1536,7 +1536,7 @@ var app = &cli.App{ }, &cli.StringSliceFlag{ Name: trainFlagModelLabels, - Usage: "labels to train on. this will either be classification or object detection labels", + Usage: "labels to train on. these will either be classification or object detection labels", Required: true, }, &cli.StringFlag{ @@ -1593,7 +1593,7 @@ var app = &cli.App{ }, &cli.StringSliceFlag{ Name: mlTrainingFlagArgs, - Usage: "command line arguments to run the training script with, should be formatted as option1=value1,option2=value2", + Usage: "command line arguments to run the training script with. should be formatted as option1=value1,option2=value2", }, }, Action: createCommandWithT[mlSubmitCustomTrainingJobArgs](MLSubmitCustomTrainingJob), @@ -1650,15 +1650,15 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: mlTrainingFlagFramework, - Usage: fmt.Sprintf("framework of the ML training script to upload, can be: [%s]", strings.Join(modelFrameworks, ", ")), + Usage: fmt.Sprintf("framework of the ML training script to upload. can be: [%s]", strings.Join(modelFrameworks, ", ")), }, &cli.StringFlag{ Name: trainFlagModelType, - Usage: fmt.Sprintf("task type of the ML training script to upload, can be: [%s]", strings.Join(modelTypes, ", ")), + Usage: fmt.Sprintf("task type of the ML training script to upload. can be: [%s]", strings.Join(modelTypes, ", ")), }, &cli.StringSliceFlag{ Name: mlTrainingFlagArgs, - Usage: "command line arguments to run the training script with, should be formatted as option1=value1,option2=value2", + Usage: "command line arguments to run the training script with. should be formatted as option1=value1,option2=value2", }, }, Action: createCommandWithT[mlSubmitCustomTrainingJobWithUploadArgs](MLSubmitCustomTrainingJobWithUpload), @@ -2399,7 +2399,8 @@ Example: Value: ".", }, &cli.StringSliceFlag{ - Name: moduleBuildFlagPlatforms, + Name: moduleBuildFlagPlatforms, + // would use 'DefaultText' key, but defaults don't show for slice flags Usage: "list of platforms to build, e.g. linux/amd64,linux/arm64 (default: build.arch in meta.json)", }, }, @@ -2558,7 +2559,7 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: generalFlagVersion, - Usage: "version of the requested package, can be `latest` to get the most recent version", + Usage: "version of the requested package. can be `latest` to get the most recent version", Value: "latest", }, &cli.StringFlag{ @@ -2599,13 +2600,13 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: generalFlagVersion, - Usage: "version of the requested package, can be `latest` to get the most recent version", + Usage: "version of the requested package. can be `latest` to get the most recent version", Value: "latest", }, &cli.StringFlag{ Name: generalFlagType, Required: true, - Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), + Usage: fmt.Sprintf("type of the requested package. can be one of: [%s]", strings.Join(packageTypes, ", ")), }, }, Action: createCommandWithT[packageExportArgs](PackageExportAction), @@ -2635,17 +2636,17 @@ This won't work unless you have an existing installation of our GitHub app on yo &cli.StringFlag{ Name: generalFlagVersion, Required: true, - Usage: "version of the requested package, can be `latest` to get the most recent version", + Usage: "version of the requested package. can be `latest` to get the most recent version", }, &cli.StringFlag{ Name: generalFlagType, Required: true, - Usage: fmt.Sprintf("type of the requested package, can be: [%s]", strings.Join(packageTypes, ", ")), + Usage: fmt.Sprintf("type of the requested package. can be: [%s]", strings.Join(packageTypes, ", ")), }, &cli.StringFlag{ Name: packageFlagFramework, Usage: fmt.Sprintf( - "framework for an ml_model being uploaded, can be: [%s]. Required if packages is of type 'ml_model'", + "framework for an ml_model being uploaded. can be: [%s]. Required if packages is of type 'ml_model'", strings.Join(modelFrameworks, ", "), ), }, @@ -2686,11 +2687,11 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: mlTrainingFlagFramework, - Usage: fmt.Sprintf("framework of the ML training script to upload, can be: [%s]", strings.Join(modelFrameworks, ", ")), + Usage: fmt.Sprintf("framework of the ML training script to upload. can be: [%s]", strings.Join(modelFrameworks, ", ")), }, &cli.StringFlag{ Name: generalFlagType, - Usage: fmt.Sprintf("task type of the ML training script to upload, can be: [%s]", strings.Join(modelTypes, ", ")), + Usage: fmt.Sprintf("task type of the ML training script to upload. can be: [%s]", strings.Join(modelTypes, ", ")), }, &cli.BoolFlag{ Name: mlTrainingFlagDraft, @@ -2722,7 +2723,7 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: mlTrainingFlagVisibility, - Usage: "visibility of the registry item, can be: ['public', 'private']", + Usage: "visibility of the registry item. can be: ['public', 'private']", Required: true, }, &cli.StringFlag{ From 934b226349761a79c67520fc0776df3bfe41039f Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Mon, 13 Jan 2025 12:47:18 -0500 Subject: [PATCH 31/38] generalize format accepted values --- cli/app.go | 92 ++++++++++++++++++++++++++-------------------- cli/ml_training.go | 4 +- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/cli/app.go b/cli/app.go index 6fe7e5de310..073fa93d687 100644 --- a/cli/app.go +++ b/cli/app.go @@ -365,9 +365,9 @@ func createUsageText(command string, requiredFlags []string, unrequiredOptions, } // formatAcceptedValues is a helper for formatting the usage text for flags that only accept certain values. -func formatAcceptedValues(values ...string) string { +func formatAcceptedValues(description string, values ...string) string { joined := strings.Join(values, ", ") - return "[" + joined + "]" + return fmt.Sprintf("%s. must be one of: [%s]", description, joined) } var app = &cli.App{ @@ -588,23 +588,27 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: oauthAppFlagClientAuthentication, - Usage: "updated client authentication policy for the OAuth application. can be one of " + - formatAcceptedValues(string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), - string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE)), + Usage: formatAcceptedValues( + "updated client authentication policy for the OAuth application", + string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), + string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE), + ), Value: unspecified, }, &cli.StringFlag{ Name: oauthAppFlagURLValidation, - Usage: "updated url validation for the OAuth application. can be one of " + - formatAcceptedValues(string(URLValidationUnspecified), string(URLValidationExactMatch), - string(URLValidationAllowWildcards)), + Usage: formatAcceptedValues( + "updated url validation for the OAuth application", + string(URLValidationUnspecified), string(URLValidationExactMatch), string(URLValidationAllowWildcards), + ), Value: unspecified, }, &cli.StringFlag{ Name: oauthAppFlagPKCE, - Usage: "updated pkce for the OAuth application. can be one of " + - formatAcceptedValues(string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), - string(PKCENotRequiredWhenUsingClientAuthentication)), + Usage: formatAcceptedValues( + "updated pkce for the OAuth application", + string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), string(PKCENotRequiredWhenUsingClientAuthentication), + ), Value: unspecified, }, &cli.StringSliceFlag{ @@ -621,9 +625,11 @@ var app = &cli.App{ }, &cli.StringSliceFlag{ Name: oauthAppFlagEnabledGrants, - Usage: "updated comma separated enabled grants for the OAuth application. values can be of " + - formatAcceptedValues(string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword), - string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode)), + Usage: formatAcceptedValues( + "updated comma separated enabled grants for the OAuth application", + string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword), + string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode), + ), }, }, Action: createCommandWithT[updateOAuthAppArgs](UpdateOAuthAppAction), @@ -649,23 +655,27 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: oauthAppFlagClientAuthentication, - Usage: "client authentication policy for the OAuth application. can be one of " + - formatAcceptedValues(string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), - string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE)), + Usage: formatAcceptedValues( + "client authentication policy for the OAuth application", + string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), + string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE), + ), Required: true, }, &cli.StringFlag{ Name: oauthAppFlagURLValidation, - Usage: "url validation for the OAuth application. can be one of " + - formatAcceptedValues(string(URLValidationUnspecified), string(URLValidationExactMatch), - string(URLValidationAllowWildcards)), + Usage: formatAcceptedValues( + "url validation for the OAuth application", + string(URLValidationUnspecified), string(URLValidationExactMatch), string(URLValidationAllowWildcards), + ), Required: true, }, &cli.StringFlag{ Name: oauthAppFlagPKCE, - Usage: "pkce for the OAuth application. can be one of " + - formatAcceptedValues(string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), - string(PKCENotRequiredWhenUsingClientAuthentication)), + Usage: formatAcceptedValues( + "pkce for the OAuth application", + string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), string(PKCENotRequiredWhenUsingClientAuthentication), + ), Required: true, }, &cli.StringSliceFlag{ @@ -684,9 +694,11 @@ var app = &cli.App{ }, &cli.StringSliceFlag{ Name: oauthAppFlagEnabledGrants, - Usage: "comma-separated enabled grants for the OAuth application. requires at least one, where values can be of " + - formatAcceptedValues(string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword), - string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode)), + Usage: formatAcceptedValues( + "comma-separated enabled grants for the OAuth application", + string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword), + string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode), + ), Required: true, }, }, @@ -1530,8 +1542,11 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: trainFlagModelType, - Usage: "type of model to train. can be one of [single_label_classification, multi_label_classification, or object_detection]", + Name: trainFlagModelType, + Usage: formatAcceptedValues( + "type of model to train", + "single_label_classification", "multi_label_classification", "object_detection", + ), Required: true, }, &cli.StringSliceFlag{ @@ -1650,11 +1665,11 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: mlTrainingFlagFramework, - Usage: fmt.Sprintf("framework of the ML training script to upload. can be: [%s]", strings.Join(modelFrameworks, ", ")), + Usage: formatAcceptedValues("framework of the ML training script to upload", modelFrameworks...), }, &cli.StringFlag{ Name: trainFlagModelType, - Usage: fmt.Sprintf("task type of the ML training script to upload. can be: [%s]", strings.Join(modelTypes, ", ")), + Usage: formatAcceptedValues("task type of the ML training script to upload", modelTypes...), }, &cli.StringSliceFlag{ Name: mlTrainingFlagArgs, @@ -1718,7 +1733,7 @@ var app = &cli.App{ }, &cli.StringFlag{ Name: trainFlagJobStatus, - Usage: "training status to filter for. can be: " + allTrainingStatusValues(), + Usage: formatAcceptedValues("training status to filter for", allTrainingStatusValues()...), Value: defaultTrainingStatus(), }, }, @@ -2606,7 +2621,7 @@ This won't work unless you have an existing installation of our GitHub app on yo &cli.StringFlag{ Name: generalFlagType, Required: true, - Usage: fmt.Sprintf("type of the requested package. can be one of: [%s]", strings.Join(packageTypes, ", ")), + Usage: formatAcceptedValues("type of the requested package", packageTypes...), }, }, Action: createCommandWithT[packageExportArgs](PackageExportAction), @@ -2641,13 +2656,12 @@ This won't work unless you have an existing installation of our GitHub app on yo &cli.StringFlag{ Name: generalFlagType, Required: true, - Usage: fmt.Sprintf("type of the requested package. can be: [%s]", strings.Join(packageTypes, ", ")), + Usage: formatAcceptedValues("type of the requested package", packageTypes...), }, &cli.StringFlag{ Name: packageFlagFramework, - Usage: fmt.Sprintf( - "framework for an ml_model being uploaded. can be: [%s]. Required if packages is of type 'ml_model'", - strings.Join(modelFrameworks, ", "), + Usage: formatAcceptedValues( + "framework for an ml_model being uploaded. Required if packages is of type 'ml_model'", modelFrameworks..., ), }, }, @@ -2687,11 +2701,11 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: mlTrainingFlagFramework, - Usage: fmt.Sprintf("framework of the ML training script to upload. can be: [%s]", strings.Join(modelFrameworks, ", ")), + Usage: formatAcceptedValues("framework of the ML training script to upload", modelFrameworks...), }, &cli.StringFlag{ Name: generalFlagType, - Usage: fmt.Sprintf("task type of the ML training script to upload. can be: [%s]", strings.Join(modelTypes, ", ")), + Usage: formatAcceptedValues("task type of the ML training script to upload", modelTypes...), }, &cli.BoolFlag{ Name: mlTrainingFlagDraft, @@ -2723,7 +2737,7 @@ This won't work unless you have an existing installation of our GitHub app on yo }, &cli.StringFlag{ Name: mlTrainingFlagVisibility, - Usage: "visibility of the registry item. can be: ['public', 'private']", + Usage: formatAcceptedValues("visibility of the registry item", "public", "private"), Required: true, }, &cli.StringFlag{ diff --git a/cli/ml_training.go b/cli/ml_training.go index 3223f02e1c0..a30aec91a05 100644 --- a/cli/ml_training.go +++ b/cli/ml_training.go @@ -356,7 +356,7 @@ func (c *viamClient) dataListTrainingJobs(orgID, status string) ([]*mltrainingpb } // allTrainingStatusValues returns the accepted values for the trainFlagJobStatus flag. -func allTrainingStatusValues() string { +func allTrainingStatusValues() []string { var formattedStatuses []string for status := range mltrainingpb.TrainingStatus_value { formattedStatus := strings.ToLower(strings.TrimPrefix(status, trainingStatusPrefix)) @@ -364,7 +364,7 @@ func allTrainingStatusValues() string { } slices.Sort(formattedStatuses) - return "[" + strings.Join(formattedStatuses, ", ") + "]" + return formattedStatuses } func defaultTrainingStatus() string { From 3a59aa283bedf077508a36f53328f12d7d1d8016 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 12:37:14 -0500 Subject: [PATCH 32/38] add pr feedback --- cli/app.go | 9 +++++---- cli/module_build.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cli/app.go b/cli/app.go index 073fa93d687..e2439226432 100644 --- a/cli/app.go +++ b/cli/app.go @@ -367,7 +367,7 @@ func createUsageText(command string, requiredFlags []string, unrequiredOptions, // formatAcceptedValues is a helper for formatting the usage text for flags that only accept certain values. func formatAcceptedValues(description string, values ...string) string { joined := strings.Join(values, ", ") - return fmt.Sprintf("%s. must be one of: [%s]", description, joined) + return fmt.Sprintf("%s. value(s) can be: [%s]", description, joined) } var app = &cli.App{ @@ -906,7 +906,7 @@ var app = &cli.App{ { Name: "list", Usage: "list locations for the current user", - UsageText: createUsageText("locations list", nil, true, false), + UsageText: "viam locations list [--organization=]", Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagOrganization, @@ -1660,8 +1660,9 @@ var app = &cli.App{ Required: true, }, &cli.StringFlag{ - Name: generalFlagVersion, - Usage: "version of the ML training script to upload. defaults to current timestamp if unspecified.", + Name: generalFlagVersion, + Usage: "version of the ML training script to upload", + DefaultText: "current timestamp", }, &cli.StringFlag{ Name: mlTrainingFlagFramework, diff --git a/cli/module_build.go b/cli/module_build.go index b933de7bddf..944bc8bc2b6 100644 --- a/cli/module_build.go +++ b/cli/module_build.go @@ -177,7 +177,7 @@ func ModuleBuildListAction(cCtx *cli.Context, args moduleBuildListArgs) error { func (c *viamClient) moduleBuildListAction(cCtx *cli.Context, args moduleBuildListArgs) error { buildIDFilter := args.ID var moduleIDFilter string - // Fall back on the module manifest build filter is not present. + // Fall back on the module manifest if build id is not present. if buildIDFilter == "" { manifestPath := args.Module manifest, err := loadManifest(manifestPath) From 4cec57fed3c7c663800ceebcc0c5a6cb855e8804 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 12:42:25 -0500 Subject: [PATCH 33/38] erase comment --- cli/client.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/client.go b/cli/client.go index 275d8650b19..b629f8bfe23 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1223,8 +1223,6 @@ func machinesPartCopyFilesAction( flagArgs machinesPartCopyFilesArgs, logger logging.Logger, ) error { - // TODO(RSDK-9288) - this is brittle and inconsistent with how most data is passed. - // Move this to being a flag (but make sure existing workflows still work!) args := c.Args().Slice() if len(args) == 0 { return errNoFiles From ad6d74179a9c9f6042f5d662ad9a43493df824ca Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 12:47:18 -0500 Subject: [PATCH 34/38] make lint --- cli/app.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/app.go b/cli/app.go index e15c35eee86..7a2dc37af89 100644 --- a/cli/app.go +++ b/cli/app.go @@ -20,9 +20,6 @@ const ( disableProfilesFlag = "disable-profiles" profileFlagName = "profile-name" - generalFlagStart = "start" - generalFlagEnd = "end" - // TODO: RSDK-6683. quietFlag = "quiet" @@ -65,6 +62,8 @@ const ( generalFlagType = "type" generalFlagResourceSubtype = "resource-subtype" generalFlagTags = "tags" + generalFlagStart = "start" + generalFlagEnd = "end" moduleFlagLanguage = "language" moduleFlagPublicNamespace = "public-namespace" @@ -1120,7 +1119,7 @@ var app = &cli.App{ { Name: "binary", Usage: "delete binary data from Viam cloud", - UsageText: createUsageText("data delete binary", []string{dataFlagOrgIDs, dataFlagStart, dataFlagEnd}, true, false), + UsageText: createUsageText("data delete binary", []string{dataFlagOrgIDs, generalFlagStart, generalFlagEnd}, true, false), Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: dataFlagOrgIDs, From 15e04b75aa83edf83ee7653bcbdd89c8e894d258 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 13:09:59 -0500 Subject: [PATCH 35/38] make lint --- cli/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/app.go b/cli/app.go index 7a2dc37af89..1b97e1c175d 100644 --- a/cli/app.go +++ b/cli/app.go @@ -62,8 +62,8 @@ const ( generalFlagType = "type" generalFlagResourceSubtype = "resource-subtype" generalFlagTags = "tags" - generalFlagStart = "start" - generalFlagEnd = "end" + generalFlagStart = "start" + generalFlagEnd = "end" moduleFlagLanguage = "language" moduleFlagPublicNamespace = "public-namespace" From 4fe3249956bd989ded166a4b47a15120e4203b90 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 14:41:24 -0500 Subject: [PATCH 36/38] make machinespartcp a function on viamclient --- cli/app.go | 1 + cli/client.go | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/app.go b/cli/app.go index 1b97e1c175d..936651c6c07 100644 --- a/cli/app.go +++ b/cli/app.go @@ -908,6 +908,7 @@ var app = &cli.App{ { Name: "list", Usage: "list locations for the current user", + // use custom usage text to show default organization flag usage even if it isn't required UsageText: "viam locations list [--organization=]", Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/cli/client.go b/cli/client.go index b629f8bfe23..1b823c83e0e 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1214,16 +1214,15 @@ func MachinesPartCopyFilesAction(c *cli.Context, args machinesPartCopyFilesArgs) logger = logging.NewDebugLogger("cli") } - return machinesPartCopyFilesAction(c, client, args, logger) + return client.machinesPartCopyFilesAction(c, args, logger) } -func machinesPartCopyFilesAction( - c *cli.Context, - client *viamClient, +func (c *viamClient) machinesPartCopyFilesAction( + ctx *cli.Context, flagArgs machinesPartCopyFilesArgs, logger logging.Logger, ) error { - args := c.Args().Slice() + args := ctx.Args().Slice() if len(args) == 0 { return errNoFiles } @@ -1269,14 +1268,14 @@ func machinesPartCopyFilesAction( return err } - globalArgs, err := getGlobalArgs(c) + globalArgs, err := getGlobalArgs(ctx) if err != nil { return err } doCopy := func() error { if isFrom { - return client.copyFilesFromMachine( + return c.copyFilesFromMachine( flagArgs.Organization, flagArgs.Location, flagArgs.Machine, @@ -1290,7 +1289,7 @@ func machinesPartCopyFilesAction( ) } - return client.copyFilesToMachine( + return c.copyFilesToMachine( flagArgs.Organization, flagArgs.Location, flagArgs.Machine, From 74682e7711d6e4bee16bdd3d92e73316833ede4d Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 14:47:55 -0500 Subject: [PATCH 37/38] update tests --- cli/app.go | 4 ++-- cli/client_test.go | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cli/app.go b/cli/app.go index 936651c6c07..90f7c81dc1c 100644 --- a/cli/app.go +++ b/cli/app.go @@ -906,8 +906,8 @@ var app = &cli.App{ HideHelpCommand: true, Subcommands: []*cli.Command{ { - Name: "list", - Usage: "list locations for the current user", + Name: "list", + Usage: "list locations for the current user", // use custom usage text to show default organization flag usage even if it isn't required UsageText: "viam locations list [--organization=]", Flags: []cli.Flag{ diff --git a/cli/client_test.go b/cli/client_test.go index 3e93e51d605..6b2fe043eba 100644 --- a/cli/client_test.go +++ b/cli/client_test.go @@ -875,7 +875,7 @@ func TestShellFileCopy(t *testing.T) { t.Run("no arguments or files", func(t *testing.T) { cCtx, viamClient, _, _ := setup(asc, nil, nil, nil, partFlags, "token") test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldEqual, errNoFiles) }) @@ -883,13 +883,13 @@ func TestShellFileCopy(t *testing.T) { args := []string{"machine:path"} cCtx, viamClient, _, _ := setup(asc, nil, nil, nil, partFlags, "token", args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldEqual, errLastArgOfFromMissing) args = []string{"path"} cCtx, viamClient, _, _ = setup(asc, nil, nil, nil, partFlags, "token", args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldEqual, errLastArgOfToMissing) }) @@ -897,7 +897,7 @@ func TestShellFileCopy(t *testing.T) { args := []string{"machine:path", "path2", "machine:path3", "destination"} cCtx, viamClient, _, _ := setup(asc, nil, nil, nil, partFlags, "token", args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldHaveSameTypeAs, copyFromPathInvalidError{}) }) @@ -911,7 +911,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) @@ -930,7 +930,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(filepath.Join(tempDir, "foo")) @@ -946,7 +946,7 @@ func TestShellFileCopy(t *testing.T) { t.Log("without recursion set") cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) - err := machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger) + err := viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger) test.That(t, errors.Is(err, errDirectoryCopyRequestNoRecursion), test.ShouldBeTrue) _, err = os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) test.That(t, errors.Is(err, fs.ErrNotExist), test.ShouldBeTrue) @@ -958,7 +958,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ = setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) test.That(t, shelltestutils.DirectoryContentsEqual(tfs.Root, filepath.Join(tempDir, filepath.Base(tfs.Root))), test.ShouldBeNil) }) @@ -977,7 +977,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) @@ -1013,7 +1013,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) test.That(t, shelltestutils.DirectoryContentsEqual(tfs.Root, filepath.Join(tempDir, filepath.Base(tfs.Root))), test.ShouldBeNil) @@ -1041,7 +1041,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) @@ -1059,7 +1059,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(randomPath) @@ -1075,7 +1075,7 @@ func TestShellFileCopy(t *testing.T) { t.Log("without recursion set") cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlags, "token", partFqdn, args...) - err := machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger) + err := viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger) test.That(t, errors.Is(err, errDirectoryCopyRequestNoRecursion), test.ShouldBeTrue) _, err = os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) test.That(t, errors.Is(err, fs.ErrNotExist), test.ShouldBeTrue) @@ -1087,7 +1087,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ = setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) test.That(t, shelltestutils.DirectoryContentsEqual(tfs.Root, filepath.Join(tempDir, filepath.Base(tfs.Root))), test.ShouldBeNil) }) @@ -1106,7 +1106,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) rd, err := os.ReadFile(filepath.Join(tempDir, filepath.Base(tfs.SingleFileNested))) @@ -1142,7 +1142,7 @@ func TestShellFileCopy(t *testing.T) { cCtx, viamClient, _, _ := setupWithRunningPart( t, asc, nil, nil, partFlagsCopy, "token", partFqdn, args...) test.That(t, - machinesPartCopyFilesAction(cCtx, viamClient, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), + viamClient.machinesPartCopyFilesAction(cCtx, parseStructFromCtx[machinesPartCopyFilesArgs](cCtx), logger), test.ShouldBeNil) test.That(t, shelltestutils.DirectoryContentsEqual(tfs.Root, filepath.Join(tempDir, filepath.Base(tfs.Root))), test.ShouldBeNil) From 16528ca22dd32f6cc63bf57a2688e72c5a29c1bb Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Thu, 16 Jan 2025 15:02:47 -0500 Subject: [PATCH 38/38] merge fixes --- cli/app.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cli/app.go b/cli/app.go index 4a67deb7bd6..4150c0bc83d 100644 --- a/cli/app.go +++ b/cli/app.go @@ -1898,7 +1898,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -1930,7 +1930,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -1975,7 +1975,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -1991,8 +1991,8 @@ var app = &cli.App{ }, &AliasStringFlag{ cli.StringFlag{ - Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, + Name: generalFlagMachine, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, }, }, }, @@ -2006,7 +2006,7 @@ var app = &cli.App{ &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, }, @@ -2055,7 +2055,7 @@ Organization and location are required flags if the machine/part name are not un Flags: []cli.Flag{ &cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, &cli.StringFlag{ @@ -2068,8 +2068,8 @@ Organization and location are required flags if the machine/part name are not un }, &AliasStringFlag{ cli.StringFlag{ - Name: generalFlagMachine, - Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, + Name: generalFlagMachine, + Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, }, }, }, @@ -2089,19 +2089,19 @@ Copy a single file to the machine with a new name: 'viam machine part cp --organization "org" --location "location" --machine "m1" --part "m1-main" my_file machine:/home/user/' Recursively copy a directory to the machine with the same name: -'viam machine part cp --machine "m1" --part "m1-main" -r my_dir machine:/home/user/' +'viam machine part cp --part "m1-main" -r my_dir machine:/home/user/' Copy multiple files to the machine with recursion and keep original permissions and metadata: -'viam machine part cp --machine "m1" --part "m1-main" -r -p my_dir my_file machine:/home/user/some/existing/dir/' +'viam machine part cp --part "m1-main" -r -p my_dir my_file machine:/home/user/some/existing/dir/' Copy a single file from the machine to a local destination: -'viam machine part cp --machine "m1" --part "m1-main" machine:my_file ~/Downloads/' +'viam machine part cp --part "m1-main" machine:my_file ~/Downloads/' Recursively copy a directory from the machine to a local destination with the same name: -'viam machine part cp --machine "m1" --part "m1-main" -r machine:my_dir ~/Downloads/' +'viam machine part cp --part "m1-main" -r machine:my_dir ~/Downloads/' Copy multiple files from the machine to a local destination with recursion and keep original permissions and metadata: -'viam machine part cp --machine "m1" --part "m1-main" -r -p machine:my_dir machine:my_file ~/some/existing/dir/' +'viam machine part cp --part "m1-main" -r -p machine:my_dir machine:my_file ~/some/existing/dir/' `, UsageText: createUsageText( "machines part cp", @@ -2112,7 +2112,7 @@ Copy multiple files from the machine to a local destination with recursion and k &AliasStringFlag{ cli.StringFlag{ Name: generalFlagPart, - Aliases: []string{generalFlagPartID, generalFlagAliasPartName}, + Aliases: []string{generalFlagPartID, generalFlagPartName}, Required: true, }, },