Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ anytype service install
anytype service start

# Create a new bot account
anytype auth create
anytype auth create <name>

# Join a space via invite link
anytype space join <invite-link>
Expand Down Expand Up @@ -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 <name> # Create a new account
anytype space list # List all available spaces

Use "anytype <command> --help" for more information about a command.
Expand Down Expand Up @@ -138,7 +138,7 @@ Manage your Anytype account and authentication:

```bash
# Create a new account
anytype auth create
anytype auth create <name>

# Log in to your account
anytype auth login
Expand All @@ -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 <name>

# List all API keys
anytype auth apikey list
Expand Down
2 changes: 1 addition & 1 deletion cmd/auth/apikey/revoke/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewRevokeCmd() *cobra.Command {
Use: "revoke <id>",
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]

Expand Down
22 changes: 6 additions & 16 deletions cmd/auth/create/create.go
Original file line number Diff line number Diff line change
@@ -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 <name>",
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 {
Expand Down Expand Up @@ -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")

Expand Down
16 changes: 6 additions & 10 deletions cmd/auth/create/create_test.go
Original file line number Diff line number Diff line change
@@ -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 <name>" {
t.Errorf("Use = %v, want create <name>", 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")
}
Expand All @@ -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")
}
Expand Down
Loading