diff --git a/README.md b/README.md index 5bcf8f4..b8c5651 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ anytype service install anytype service start # Create a new bot account -anytype auth create +anytype auth create # Join a space via invite link anytype space join @@ -74,7 +74,7 @@ Examples: anytype service install # Install as user service anytype service start # Start the service anytype auth login # Log in to your account - anytype auth create # Create a new account + anytype auth create # Create a new account anytype space list # List all available spaces Use "anytype --help" for more information about a command. @@ -138,7 +138,7 @@ Manage your Anytype account and authentication: ```bash # Create a new account -anytype auth create +anytype auth create # Log in to your account anytype auth login @@ -156,7 +156,7 @@ Manage API keys for programmatic access: ```bash # Create a new API key -anytype auth apikey create --name "my-app" +anytype auth apikey create # List all API keys anytype auth apikey list diff --git a/cmd/auth/apikey/revoke/revoke.go b/cmd/auth/apikey/revoke/revoke.go index c1ebc39..0799d8f 100644 --- a/cmd/auth/apikey/revoke/revoke.go +++ b/cmd/auth/apikey/revoke/revoke.go @@ -13,7 +13,7 @@ func NewRevokeCmd() *cobra.Command { Use: "revoke ", Short: "Revoke an API key", Long: "Revoke an API key by its Id", - Args: cmdutil.ExactArgs(1, "cannot revoke API key: Id argument required"), + Args: cmdutil.ExactArgs(1, "cannot revoke API key: id argument required"), RunE: func(cmd *cobra.Command, args []string) error { appId := args[0] diff --git a/cmd/auth/create/create.go b/cmd/auth/create/create.go index 0051074..d4dd2ad 100644 --- a/cmd/auth/create/create.go +++ b/cmd/auth/create/create.go @@ -1,38 +1,29 @@ package create import ( - "bufio" "fmt" - "os" "strings" + "github.com/spf13/cobra" + + "github.com/anyproto/anytype-cli/cmd/cmdutil" "github.com/anyproto/anytype-cli/core" "github.com/anyproto/anytype-cli/core/config" "github.com/anyproto/anytype-cli/core/output" - "github.com/spf13/cobra" ) // NewCreateCmd creates the auth create command func NewCreateCmd() *cobra.Command { - var name string var rootPath string var listenAddress string cmd := &cobra.Command{ - Use: "create", + Use: "create ", Short: "Create a new bot account", Long: "Create a new Anytype bot account with a generated account key. The account key is your credential for bot authentication.", + Args: cmdutil.ExactArgs(1, "cannot create account: name argument required"), RunE: func(cmd *cobra.Command, args []string) error { - if name == "" { - output.Print("Enter account name: ") - reader := bufio.NewReader(os.Stdin) - name, _ = reader.ReadString('\n') - name = strings.TrimSpace(name) - - if name == "" { - return output.Error("account name is required") - } - } + name := args[0] accountKey, accountId, savedToKeyring, err := core.CreateWallet(name, rootPath, listenAddress) if err != nil { @@ -83,7 +74,6 @@ func NewCreateCmd() *cobra.Command { }, } - cmd.Flags().StringVar(&name, "name", "", "Account name") cmd.Flags().StringVar(&rootPath, "root-path", "", "Root path for account data") cmd.Flags().StringVar(&listenAddress, "listen-address", config.DefaultAPIAddress, "API listen address in `host:port` format") diff --git a/cmd/auth/create/create_test.go b/cmd/auth/create/create_test.go index bc53fae..bfd6b66 100644 --- a/cmd/auth/create/create_test.go +++ b/cmd/auth/create/create_test.go @@ -1,20 +1,16 @@ package create import ( - "strings" "testing" ) func TestCreateCommand(t *testing.T) { cmd := NewCreateCmd() - if cmd.Use != "create" { - t.Errorf("Use = %v, want create", cmd.Use) + if cmd.Use != "create " { + t.Errorf("Use = %v, want create ", cmd.Use) } - if cmd.Flag("name") == nil { - t.Error("name flag not found") - } if cmd.Flag("root-path") == nil { t.Error("root-path flag not found") } @@ -23,12 +19,12 @@ func TestCreateCommand(t *testing.T) { } } -func TestCreateCommandInteractiveInput(t *testing.T) { +func TestCreateCommandRequiresName(t *testing.T) { cmd := NewCreateCmd() - cmd.SetIn(strings.NewReader("TestAccount\n")) - cmd.SetArgs([]string{}) - + if cmd.Args == nil { + t.Error("Args validator is not set") + } if cmd.RunE == nil { t.Error("RunE function is not set") }