Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI Unification: audit-log, completion, connector, connector-catalog, environment, feedback, ksql, prompt, schema-registry, shell, update, version #931

Merged
merged 53 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5d58f3d
unify config command
brianstrauch Jun 30, 2021
061202c
unified config file, IsCloud and IsOnPrem
brianstrauch Jun 30, 2021
c529ea9
consolidate ccloud hostnames var
brianstrauch Jun 30, 2021
44b69b2
finish config unification and test
brianstrauch Jul 1, 2021
6c000c9
add golden files
brianstrauch Jul 1, 2021
c3cd7d5
check for test url second
brianstrauch Jul 2, 2021
4cd08a3
add back missing return
brianstrauch Jul 2, 2021
cbe8d2e
fix merge conflicts
brianstrauch Jul 6, 2021
6f896d3
fix merge conflicts
brianstrauch Jul 6, 2021
f8c43b6
unify root command
brianstrauch Jul 7, 2021
bf28fa1
CLI Unification: Config (#914)
brianstrauch Jul 7, 2021
7d80078
unified config file, IsCloud and IsOnPrem
brianstrauch Jun 30, 2021
312f7e8
finish config unification and test
brianstrauch Jul 1, 2021
183ffd4
unify root command
brianstrauch Jul 7, 2021
ae50ac5
Merge branch 'main' into unify-confluent
brianstrauch Jul 7, 2021
dbd59c8
fix lint
brianstrauch Jul 7, 2021
e498408
remove dead code
brianstrauch Jul 8, 2021
d2e854b
add back accidentally deleted files
brianstrauch Jul 8, 2021
74455d1
fix unit test for windows
brianstrauch Jul 8, 2021
b5a4297
trigger build
brianstrauch Jul 8, 2021
3023e27
remove cliname references
brianstrauch Jul 8, 2021
fc384ec
remove cliname references
brianstrauch Jul 8, 2021
0a06fe1
remove cliname references
brianstrauch Jul 8, 2021
82ddf67
move automaticenv back
brianstrauch Jul 9, 2021
e513791
change help command description based on context
brianstrauch Jul 9, 2021
f33bba3
lint no-context commands
brianstrauch Jul 9, 2021
119aca3
move local and kafka to no-context section
brianstrauch Jul 10, 2021
6a8f82e
add suggestion to long description
brianstrauch Jul 12, 2021
6e826ad
hide local command if windows
brianstrauch Jul 12, 2021
4e273b6
Merge branch 'unify-prompt' into unify-misc
brianstrauch Jul 12, 2021
d523b62
Merge branch 'unify-version' into unify-misc
brianstrauch Jul 12, 2021
3075ac0
Merge branch 'unify-confluent' into unify-misc
brianstrauch Jul 12, 2021
9c51d86
unify audit-log and fix tests
brianstrauch Jul 12, 2021
b725da0
unify ksql
brianstrauch Jul 12, 2021
554e052
unify feedback
brianstrauch Jul 12, 2021
f6e4e1c
Merge branch 'main' into unify-misc
brianstrauch Jul 21, 2021
067b9bd
unify connector
brianstrauch Jul 21, 2021
fb9b900
unify connector-catalog
brianstrauch Jul 21, 2021
575f5b9
unify environment
brianstrauch Jul 21, 2021
5e31db3
fix connector-catalog test
brianstrauch Jul 21, 2021
f43e6b8
fix lint
brianstrauch Jul 21, 2021
f657a85
fix int tests
brianstrauch Jul 21, 2021
b8f5415
unify schema-registry
brianstrauch Jul 22, 2021
fed77d5
fix int tests
brianstrauch Jul 22, 2021
4b92fa8
unify shell
brianstrauch Jul 22, 2021
73a57e9
fix unit tests
brianstrauch Jul 22, 2021
ed97b3f
unify update
brianstrauch Jul 22, 2021
58ba380
fix int tests
brianstrauch Jul 22, 2021
4da7f13
fix schema-registry cluster description
brianstrauch Jul 28, 2021
bc9069e
Merge branch 'main' into unify-misc
brianstrauch Jul 28, 2021
b5d02ae
add long description for schema-registry cluster
brianstrauch Jul 28, 2021
0e51c7a
Merge branch 'main' into unify-misc
brianstrauch Jul 28, 2021
b7e9d73
fix int tests
brianstrauch Jul 29, 2021
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
11 changes: 6 additions & 5 deletions internal/cmd/audit-log/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
v3 "github.com/confluentinc/cli/internal/pkg/config/v3"
"github.com/confluentinc/cli/internal/pkg/errors"
)

Expand All @@ -18,7 +19,7 @@ type command struct {
}

// New returns the default command object for interacting with audit logs.
func New(cliName string, prerunner pcmd.PreRunner) *cobra.Command {
func New(cfg *v3.Config, prerunner pcmd.PreRunner) *cobra.Command {
cliCmd := pcmd.NewCLICommand(
&cobra.Command{
Use: "audit-log",
Expand All @@ -29,14 +30,14 @@ func New(cliName string, prerunner pcmd.PreRunner) *cobra.Command {
CLICommand: cliCmd,
prerunner: prerunner,
}
cmd.init(cliName)
cmd.init(cfg)
return cmd.Command
}

func (c *command) init(cliName string) {
if cliName == "ccloud" {
func (c *command) init(cfg *v3.Config) {
if cfg.IsCloud() {
c.AddCommand(NewDescribeCommand(c.prerunner))
} else if cliName == "confluent" {
} else {
c.AddCommand(NewMigrateCommand(c.prerunner))
c.AddCommand(NewConfigCommand(c.prerunner))
c.AddCommand(NewRouteCommand(c.prerunner))
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/audit-log/command_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ func mockAuditLogCommand(configured bool) *cobra.Command {
TopicName: "confluent-audit-log-events",
}
}
return New("ccloud", climock.NewPreRunnerMock(client, nil, nil, cfg))

return New(cfg, climock.NewPreRunnerMock(client, nil, nil, cfg))
}
2 changes: 1 addition & 1 deletion internal/cmd/audit-log/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (suite *AuditConfigTestSuite) newMockCmd(expect chan MockCall) *cobra.Comma
}
mdsClient := mds.NewAPIClient(mds.NewConfiguration())
mdsClient.AuditLogConfigurationApi = suite.mockApi
return New("confluent", cliMock.NewPreRunnerMock(nil, mdsClient, nil, suite.conf))
return New(suite.conf, cliMock.NewPreRunnerMock(nil, mdsClient, nil, suite.conf))
}

func TestAuditConfigTestSuite(t *testing.T) {
Expand Down
28 changes: 14 additions & 14 deletions internal/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ func NewConfluentCommand(cfg *v3.Config, isTest bool, ver *pversion.Version) *co
isAPIKeyLogin := isAPIKeyCredential(cfg)

// No-login commands
cli.AddCommand(completion.New(cli, cliName))
cli.AddCommand(completion.New(cli))
cli.AddCommand(config.New(cfg.IsCloud(), prerunner, analyticsClient))
cli.AddCommand(kafka.New(isAPIKeyLogin, cliName, prerunner, logger.Named("kafka"), ver.ClientID, serverCompleter, analyticsClient))
cli.AddCommand(local.New(prerunner))
cli.AddCommand(login.New(prerunner, logger, ccloudClientFactory, mdsClientManager, analyticsClient, netrcHandler, loginCredentialsManager, authTokenHandler, isTest).Command)
cli.AddCommand(logout.New(cliName, prerunner, analyticsClient, netrcHandler).Command)
cli.AddCommand(secret.New(flagResolver, secrets.NewPasswordProtectionPlugin(logger)))
if !cfg.DisableUpdates {
cli.AddCommand(update.New(cliName, logger, ver, updateClient, analyticsClient))
cli.AddCommand(update.New(logger, ver, updateClient, analyticsClient))
}
cli.AddCommand(version.New(cliName, prerunner, ver))
cli.AddCommand(version.New(prerunner, ver))

if cfg.IsCloud() {
cli.AddCommand(admin.New(prerunner, isTest))
cli.AddCommand(auditlog.New(cliName, prerunner))
cli.AddCommand(auditlog.New(cfg, prerunner))
cli.AddCommand(initcontext.New(prerunner, flagResolver, analyticsClient))

// If a user logs in with an API key, don't allow the remaining commands.
Expand All @@ -152,9 +152,9 @@ func NewConfluentCommand(cfg *v3.Config, isTest bool, ver *pversion.Version) *co
}

apiKeyCmd := apikey.New(prerunner, nil, flagResolver, analyticsClient)
connectorCmd := connector.New(cliName, prerunner, analyticsClient)
connectorCatalogCmd := connectorcatalog.New(cliName, prerunner)
environmentCmd := environment.New(cliName, prerunner, analyticsClient)
connectorCmd := connector.New(prerunner, analyticsClient)
connectorCatalogCmd := connectorcatalog.New(prerunner)
environmentCmd := environment.New(prerunner, analyticsClient)
serviceAccountCmd := serviceaccount.New(prerunner, analyticsClient)

serverCompleter.AddCommand(apiKeyCmd)
Expand All @@ -168,22 +168,22 @@ func NewConfluentCommand(cfg *v3.Config, isTest bool, ver *pversion.Version) *co
cli.AddCommand(connectorCmd.Command)
cli.AddCommand(environmentCmd.Command)
cli.AddCommand(iam.New(cliName, prerunner))
cli.AddCommand(ksql.New(cliName, prerunner, serverCompleter, analyticsClient))
cli.AddCommand(ksql.New(cfg, prerunner, serverCompleter, analyticsClient))
cli.AddCommand(price.New(prerunner))
cli.AddCommand(prompt.New(cliName, prerunner, &ps1.Prompt{}, logger))
cli.AddCommand(schemaregistry.New(cliName, prerunner, nil, logger, analyticsClient))
cli.AddCommand(prompt.New(cfg, prerunner, &ps1.Prompt{}, logger))
cli.AddCommand(schemaregistry.New(cfg, prerunner, nil, logger, analyticsClient))
cli.AddCommand(serviceAccountCmd.Command)
cli.AddCommand(shell.NewShellCmd(cli, prerunner, cliName, cfg, shellCompleter, logger, analyticsClient, jwtValidator))
cli.AddCommand(shell.NewShellCmd(cli, prerunner, cfg, shellCompleter, logger, analyticsClient, jwtValidator))
cli.AddCommand(signup.New(prerunner, logger, ver.UserAgent, ccloudClientFactory).Command)
}

if cfg.IsOnPrem() {
cli.AddCommand(auditlog.New(cliName, prerunner))
cli.AddCommand(auditlog.New(cfg, prerunner))
cli.AddCommand(cluster.New(prerunner, cluster.NewScopedIdService(ver.UserAgent, logger)))
cli.AddCommand(connect.New(prerunner))
cli.AddCommand(iam.New(cliName, prerunner))
cli.AddCommand(ksql.New(cliName, prerunner, serverCompleter, analyticsClient))
cli.AddCommand(schemaregistry.New(cliName, prerunner, nil, logger, analyticsClient))
cli.AddCommand(ksql.New(cfg, prerunner, serverCompleter, analyticsClient))
cli.AddCommand(schemaregistry.New(cfg, prerunner, nil, logger, analyticsClient))
}

return command
Expand Down
13 changes: 7 additions & 6 deletions internal/cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
"github.com/confluentinc/cli/internal/pkg/errors"
pversion "github.com/confluentinc/cli/internal/pkg/version"
)

const longDescriptionTemplate = `Use this command to print the output Shell completion
Expand Down Expand Up @@ -83,19 +84,19 @@ type completionCommand struct {
}

// New returns the Cobra command for shell completion.
func New(rootCmd *cobra.Command, cliName string) *cobra.Command {
func New(rootCmd *cobra.Command) *cobra.Command {
cmd := &completionCommand{
rootCmd: rootCmd,
}
cmd.init(cliName)
cmd.init()
return cmd.Command
}

func (c *completionCommand) init(cliName string) {
func (c *completionCommand) init() {
c.Command = &cobra.Command{
Use: "completion <shell>",
Short: "Print shell completion code.",
Long: getLongDescription(cliName),
Long: getLongDescription(),
Args: cobra.ExactArgs(1),
RunE: pcmd.NewCLIRunE(c.completion),
}
Expand All @@ -113,10 +114,10 @@ func (c *completionCommand) completion(cmd *cobra.Command, args []string) error
return err
}

func getLongDescription(cliName string) string {
func getLongDescription() string {
t := template.Must(template.New("longDescription").Parse(longDescriptionTemplate))
buf := new(bytes.Buffer)
data := map[string]interface{}{"CLIName": cliName}
data := map[string]interface{}{"CLIName": pversion.CLIName}
if err := t.Execute(buf, data); err != nil {
// We're okay with this since its definitely a development error; should never happen to users
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestCompletionBash(t *testing.T) {
req := require.New(t)

root := pcmd.BuildRootCommand()
cmd := New(root, "ccloud")
cmd := New(root)
root.AddCommand(cmd)

output, err := pcmd.ExecuteCommand(root, "completion", "bash")
Expand All @@ -24,7 +24,7 @@ func TestCompletionZsh(t *testing.T) {
req := require.New(t)

root := pcmd.BuildRootCommand()
cmd := New(root, "ccloud")
cmd := New(root)
root.AddCommand(cmd)

output, err := pcmd.ExecuteCommand(root, "completion", "zsh")
Expand All @@ -36,7 +36,7 @@ func TestCompletionUnknown(t *testing.T) {
req := require.New(t)

root := pcmd.BuildRootCommand()
cmd := New(root, "ccloud")
cmd := New(root)
root.AddCommand(cmd)

_, err := pcmd.ExecuteCommand(root, "completion", "newsh")
Expand All @@ -48,7 +48,7 @@ func TestCompletionNone(t *testing.T) {
req := require.New(t)

root := pcmd.BuildRootCommand()
cmd := New(root, "ccloud")
cmd := New(root)
root.AddCommand(cmd)

_, err := pcmd.ExecuteCommand(root, "completion")
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/connector-catalog/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/confluentinc/cli/internal/pkg/examples"
"github.com/confluentinc/cli/internal/pkg/output"
"github.com/confluentinc/cli/internal/pkg/utils"
"github.com/confluentinc/cli/internal/pkg/version"
)

type command struct {
Expand All @@ -31,18 +32,18 @@ var (
)

// New returns the default command object for interacting with Connect.
func New(cliName string, prerunner pcmd.PreRunner) *command {
func New(prerunner pcmd.PreRunner) *command {
cmd := &command{
AuthenticatedStateFlagCommand: pcmd.NewAuthenticatedStateFlagCommand(&cobra.Command{
Use: "connector-catalog",
Short: "Catalog of connectors and their configurations.",
}, prerunner, SubcommandFlags),
}
cmd.init(cliName)
cmd.init()
return cmd
}

func (c *command) init(cliName string) {
func (c *command) init() {
describeCmd := &cobra.Command{
Use: "describe <connector-type>",
Short: "Describe a connector plugin type.",
Expand All @@ -51,7 +52,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Describe required connector configuration parameters for a specific connector plugin.",
Code: fmt.Sprintf("%s connector-catalog describe <plugin-name>", cliName),
Code: fmt.Sprintf("%s connector-catalog describe <plugin-name>", version.CLIName),
},
),
}
Expand All @@ -67,7 +68,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "List connectors in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector-catalog list", cliName),
Code: fmt.Sprintf("%s connector-catalog list", version.CLIName),
},
),
}
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/connector-catalog/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func (suite *CatalogTestSuite) SetupTest() {

func (suite *CatalogTestSuite) newCmd() *command {
prerunner := cliMock.NewPreRunnerMock(&ccloud.Client{Connect: suite.connectMock, Kafka: suite.kafkaMock}, nil, nil, suite.conf)
cmd := New("ccloud", prerunner)
return cmd
return New(prerunner)
}

func (suite *CatalogTestSuite) TestCatalogList() {
Expand Down
32 changes: 14 additions & 18 deletions internal/cmd/connector/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import (
"os"

"github.com/c-bata/go-prompt"

"github.com/confluentinc/cli/internal/pkg/examples"

"github.com/confluentinc/go-printer"
"github.com/spf13/cobra"

schedv1 "github.com/confluentinc/cc-structs/kafka/scheduler/v1"
opv1 "github.com/confluentinc/cc-structs/operator/v1"
"github.com/confluentinc/go-printer"
"github.com/spf13/cobra"

"github.com/confluentinc/cli/internal/pkg/analytics"
pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
"github.com/confluentinc/cli/internal/pkg/errors"
"github.com/confluentinc/cli/internal/pkg/examples"
"github.com/confluentinc/cli/internal/pkg/output"
"github.com/confluentinc/cli/internal/pkg/shell/completer"
"github.com/confluentinc/cli/internal/pkg/utils"
"github.com/confluentinc/cli/internal/pkg/version"
)

type command struct {
Expand Down Expand Up @@ -61,7 +59,7 @@ var (
)

// New returns the default command object for interacting with Connect.
func New(cliName string, prerunner pcmd.PreRunner, analyticsClient analytics.Client) *command {
func New(prerunner pcmd.PreRunner, analyticsClient analytics.Client) *command {
cmd := &command{
AuthenticatedStateFlagCommand: pcmd.NewAuthenticatedStateFlagCommand(
&cobra.Command{
Expand All @@ -71,11 +69,11 @@ func New(cliName string, prerunner pcmd.PreRunner, analyticsClient analytics.Cli
prerunner: prerunner,
analyticsClient: analyticsClient,
}
cmd.init(cliName)
cmd.init()
return cmd
}

func (c *command) init(cliName string) {
func (c *command) init() {
describeCmd := &cobra.Command{
Use: "describe <id>",
Short: "Describe a connector.",
Expand All @@ -84,7 +82,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Describe connector and task level details of a connector in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector describe <id>\n%s connector describe <id> --cluster <cluster-id>", cliName, cliName),
Code: fmt.Sprintf("%s connector describe <id>\n%s connector describe <id> --cluster <cluster-id>", version.CLIName, version.CLIName),
},
),
}
Expand All @@ -100,7 +98,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "List connectors in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector list\n%s connector list --cluster <cluster-id>", cliName, cliName),
Code: fmt.Sprintf("%s connector list\n%s connector list --cluster <cluster-id>", version.CLIName, version.CLIName),
},
),
}
Expand All @@ -116,7 +114,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Create a connector in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector create --config <file>\n%s connector create --cluster <cluster-id> --config <file>", cliName, cliName),
Code: fmt.Sprintf("%s connector create --config <file>\n%s connector create --cluster <cluster-id> --config <file>", version.CLIName, version.CLIName),
},
),
}
Expand All @@ -134,7 +132,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Delete a connector in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector delete --config <file>\n%s connector delete --cluster <cluster-id> --config <file>", cliName, cliName),
Code: fmt.Sprintf("%s connector delete --config <file>\n%s connector delete --cluster <cluster-id> --config <file>", version.CLIName, version.CLIName),
},
),
}
Expand All @@ -159,7 +157,7 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Pause a connector in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector pause --config <file>\n%s connector pause --cluster <cluster-id> --config <file>", cliName, cliName),
Code: fmt.Sprintf("%s connector pause --config <file>\n%s connector pause --cluster <cluster-id> --config <file>", version.CLIName, version.CLIName),
},
),
}
Expand All @@ -173,15 +171,13 @@ func (c *command) init(cliName string) {
Example: examples.BuildExampleString(
examples.Example{
Text: "Resume a connector in the current or specified Kafka cluster context.",
Code: fmt.Sprintf("%s connector resume --config <file>\n%s connector resume --cluster <cluster-id> --config <file>", cliName, cliName),
Code: fmt.Sprintf("%s connector resume --config <file>\n%s connector resume --cluster <cluster-id> --config <file>", version.CLIName, version.CLIName),
},
),
}
c.AddCommand(resumeCmd)

if cliName == "ccloud" {
c.AddCommand(NewEventCommand(c.prerunner))
}
c.AddCommand(NewEventCommand(c.prerunner))

c.completableChildren = []*cobra.Command{deleteCmd, describeCmd, pauseCmd, resumeCmd, updateCmd}
c.completableFlagChildren = map[string][]*cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/connector/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
opv1 "github.com/confluentinc/cc-structs/operator/v1"
"github.com/confluentinc/ccloud-sdk-go-v1"
ccsdkmock "github.com/confluentinc/ccloud-sdk-go-v1/mock"

"github.com/confluentinc/cli/internal/cmd/utils"
"github.com/confluentinc/cli/internal/pkg/analytics"
v3 "github.com/confluentinc/cli/internal/pkg/config/v3"
Expand Down Expand Up @@ -119,7 +120,7 @@ func (suite *ConnectTestSuite) SetupTest() {

func (suite *ConnectTestSuite) newCmd() *command {
prerunner := cliMock.NewPreRunnerMock(&ccloud.Client{Connect: suite.connectMock, Kafka: suite.kafkaMock}, nil, nil, suite.conf)
cmd := New("ccloud", prerunner, suite.analyticsClient)
cmd := New(prerunner, suite.analyticsClient)
return cmd
}

Expand Down
Loading