Skip to content

Commit 0309fed

Browse files
authored
fix: improve root command long help text and use more descriptive errors when account id or api key are missing (#66)
1 parent f304a97 commit 0309fed

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

internal/cli/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ func NewRootCommand(s *state.State) *cobra.Command {
2424
cmd := &cobra.Command{
2525
Use: "qcloud",
2626
Short: "Qdrant Cloud CLI",
27-
Long: "The command-line interface for Qdrant Cloud",
27+
Long: `The command-line interface for Qdrant Cloud.
28+
29+
Get started:
30+
qcloud context set default --api-key <KEY> --account-id <ID>
31+
qcloud cluster list
32+
33+
Documentation: https://github.com/qdrant/qcloud-cli`,
2834
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
2935
if err := s.Config.Load(configPath); err != nil {
3036
return err

internal/state/state.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package state
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"log/slog"
78

@@ -10,6 +11,11 @@ import (
1011
"github.com/qdrant/qcloud-cli/internal/state/config"
1112
)
1213

14+
var (
15+
errNoAPIKey = errors.New("no API Key configured — set QDRANT_CLOUD_API_KEY, use --api-key, or run \"qcloud context set\" to save credentials")
16+
errNoAccountID = errors.New("no account ID configured — set QDRANT_CLOUD_ACCOUNT_ID, use --account-id, or run \"qcloud context set\" to save credentials")
17+
)
18+
1319
// Updater checks for and applies CLI updates.
1420
type Updater interface {
1521
DetectLatest(ctx context.Context) (*selfupgrade.ReleaseInfo, bool, error)
@@ -42,7 +48,7 @@ func (s *State) Client(ctx context.Context) (*qcloudapi.Client, error) {
4248

4349
key := s.Config.APIKey()
4450
if key == "" {
45-
return nil, fmt.Errorf("no API Key configured — set QDRANT_CLOUD_API_KEY or use --api-key")
51+
return nil, errNoAPIKey
4652
}
4753

4854
c, err := qcloudapi.New(ctx, s.Config.Endpoint(), key, s.Version)
@@ -83,7 +89,7 @@ func (s *State) SetUpdater(u Updater) {
8389
func (s *State) AccountID() (string, error) {
8490
id := s.Config.AccountID()
8591
if id == "" {
86-
return "", fmt.Errorf("no account ID configured — set QDRANT_CLOUD_ACCOUNT_ID or use --account-id")
92+
return "", errNoAccountID
8793
}
8894
return id, nil
8995
}

0 commit comments

Comments
 (0)