* refactor(cli): migrate to Cobra-based command structure Refactor CLI to use Cobra instead of manual os.Args parsing. - Introduce root command and structured subcommands under cmd/picoclaw/internal - Convert agent, auth, cron, gateway, migrate, onboard, skills, status and version to Cobra commands - Replace manual flag parsing with Cobra flags - Remove direct os.Args usage from command handlers - Keep existing command behavior and output semantics This change focuses on CLI structure and maintainability. No business logic changes intended. * chore(cli): remove version2 alias and make cobra a direct dependency * test(cli): add basic command tests - Add tests for CLI command tree and flag parsing - Align LDFLAGS injection path for version info - Remove unused manual help function * test: migrate command tests to testify assertions Replace standard library testing error checks (t.Error*, t.Fatalf) with assert/require from stretchr/testify across all cobra command tests for improved readability and consistency. * fix(cli): make linter happy * test: avoid duplication in windows config path test * test: simplify allowed command checks using slices.Contains * fix(skills): register subcommands during command construction - Move subcommand registration out of PersistentPreRunE - Ensure `picoclaw skills <subcommand>` resolves correctly - Minor install command and test cleanups * refactor(cli): address review feedback and improve command clarity * fix(authLogoutCmd): rm os.Exit
29 lines
625 B
Go
29 lines
625 B
Go
package auth
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewLoginSubCommand(t *testing.T) {
|
|
cmd := newLoginCommand()
|
|
|
|
require.NotNil(t, cmd)
|
|
|
|
assert.Equal(t, "Login via OAuth or paste token", cmd.Short)
|
|
|
|
assert.True(t, cmd.HasFlags())
|
|
|
|
assert.NotNil(t, cmd.Flags().Lookup("device-code"))
|
|
|
|
providerFlag := cmd.Flags().Lookup("provider")
|
|
require.NotNil(t, providerFlag)
|
|
|
|
val, found := providerFlag.Annotations[cobra.BashCompOneRequiredFlag]
|
|
require.True(t, found)
|
|
require.NotEmpty(t, val)
|
|
assert.Equal(t, "true", val[0])
|
|
}
|