Skip to content

Commit

Permalink
refactor(instance): rename instances to instance (#195)
Browse files Browse the repository at this point in the history
Because

- to keep command naming consistent

This commit

- change `instances` to `instance`
  • Loading branch information
pinglin authored Oct 6, 2023
1 parent b121969 commit 23f8586
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func apiRun(opts *ApiOptions) error {
`ERROR: instance '%s' does not exist
You can add it with:
$ inst instances add %s`,
$ inst instance add %s`,
hostname, hostname))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func loginRun(f *cmdutil.Factory, opts *LoginOptions) error {
e := heredoc.Docf(`ERROR: OAuth2 config isn't complete for '%s'
You can fix it with:
$ inst instances edit %s \
$ inst instance edit %s \
--oauth2 HOSTNAME \
--client-id CLIENT_ID \
--client-secret CLIENT_SECRET`, host.APIHostname, host.APIHostname)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/auth/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func statusRun(opts *StatusOptions) error {
}
if len(hostnames) == 0 {
fmt.Fprintf(stderr,
"You are not logged into any Instill Core/Cloud instances. Run %s to authenticate.\n", cs.Bold("inst auth login"))
"You are not logged into any Instill Core/Cloud instance. Run %s to authenticate.\n", cs.Bold("inst auth login"))
return cmdutil.SilentError
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/instances/add.go → pkg/cmd/instance/add.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"fmt"
Expand Down Expand Up @@ -29,7 +29,7 @@ func NewAddCmd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command
Use: "add",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instances add API_HOSTNAME")
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instance add API_HOSTNAME")
}
if err := instance.HostnameValidator(args[0]); err != nil {
return fmt.Errorf("error parsing API hostname %w", err)
Expand All @@ -42,10 +42,10 @@ func NewAddCmd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command
`),
Example: heredoc.Doc(`
# add a local instance as the default one
$ inst instances add instill.localhost --default
$ inst instance add instill.localhost --default
# add a cloud instance
$ inst instances add api.instill.tech \
$ inst instance add api.instill.tech \
--oauth2 auth.instill.tech \
--audience https://instill.tech \
--issuer https://auth.instill.tech/ \
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/instances/add_test.go → pkg/cmd/instance/add_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"bytes"
Expand All @@ -12,7 +12,7 @@ import (
"github.com/instill-ai/cli/pkg/iostreams"
)

func TestInstancesAddCmd(t *testing.T) {
func TestInstanceAddCmd(t *testing.T) {
tests := []struct {
name string
stdin string
Expand All @@ -28,7 +28,7 @@ func TestInstancesAddCmd(t *testing.T) {
isErr: true,
},
{
name: "instances add foo --default",
name: "instance add foo --default",
input: "foo --default",
output: AddOptions{
InstanceOptions: InstanceOptions{
Expand All @@ -39,7 +39,7 @@ func TestInstancesAddCmd(t *testing.T) {
isErr: false,
},
{
name: "instances add foo --oauth2 bar",
name: "instance add foo --oauth2 bar",
input: "foo --oauth2 bar",
output: AddOptions{
InstanceOptions: InstanceOptions{
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestInstancesAddCmd(t *testing.T) {
}
}

func TestInstancesAddCmdRun(t *testing.T) {
func TestInstanceAddCmdRun(t *testing.T) {
tests := []struct {
name string
input *AddOptions
Expand All @@ -110,7 +110,7 @@ func TestInstancesAddCmdRun(t *testing.T) {
expectFn func(*testing.T, config.Config)
}{
{
name: "instances add foo --default",
name: "instance add foo --default",
input: &AddOptions{
InstanceOptions: InstanceOptions{
APIHostname: "foo",
Expand All @@ -122,7 +122,7 @@ func TestInstancesAddCmdRun(t *testing.T) {
isErr: false,
},
{
name: "instances add foo --oauth2 bar1 --client-secret bar2 --client-id bar3",
name: "instance add foo --oauth2 bar1 --client-secret bar2 --client-id bar3",
input: &AddOptions{
Config: config.ConfigStub{},
InstanceOptions: InstanceOptions{
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/instances/edit.go → pkg/cmd/instance/edit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"fmt"
Expand Down Expand Up @@ -30,7 +30,7 @@ func NewEditCmd(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
Use: "edit",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instances edit API_HOSTNAME")
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instance edit API_HOSTNAME")
}
if err := instance.HostnameValidator(args[0]); err != nil {
return fmt.Errorf("error parsing API hostname %w", err)
Expand All @@ -43,11 +43,11 @@ func NewEditCmd(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
`),
Example: heredoc.Doc(`
# update the issuer for api.instill.tech
$ inst instances edit api.instill.tech \
$ inst instance edit api.instill.tech \
--issuer https://auth.instill.tech/
# remove authentication for instill.localhost
$ inst instances edit instill.localhost --no-auth
$ inst instance edit instill.localhost --no-auth
`),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/instances/edit_test.go → pkg/cmd/instance/edit_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"bytes"
Expand All @@ -12,7 +12,7 @@ import (
"github.com/instill-ai/cli/pkg/iostreams"
)

func TestInstancesEditCmd(t *testing.T) {
func TestInstanceEditCmd(t *testing.T) {
tests := []struct {
name string
stdin string
Expand All @@ -28,7 +28,7 @@ func TestInstancesEditCmd(t *testing.T) {
isErr: true,
},
{
name: "instances edit api.instill.tech --default",
name: "instance edit api.instill.tech --default",
input: "api.instill.tech --default",
output: EditOptions{
InstanceOptions: InstanceOptions{
Expand All @@ -39,7 +39,7 @@ func TestInstancesEditCmd(t *testing.T) {
isErr: false,
},
{
name: "instances edit api.instill.tech --oauth2 bar",
name: "instance edit api.instill.tech --oauth2 bar",
input: "api.instill.tech --oauth2 bar",
output: EditOptions{
InstanceOptions: InstanceOptions{
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestInstancesEditCmd(t *testing.T) {
}
}

func TestInstancesEditCmdRun(t *testing.T) {
func TestInstanceEditCmdRun(t *testing.T) {
tests := []struct {
name string
input *EditOptions
Expand All @@ -110,7 +110,7 @@ func TestInstancesEditCmdRun(t *testing.T) {
expectFn func(*testing.T, config.Config)
}{
{
name: "instances edit api.instill.tech --default",
name: "instance edit api.instill.tech --default",
input: &EditOptions{
InstanceOptions: InstanceOptions{
APIHostname: "api.instill.tech",
Expand All @@ -122,7 +122,7 @@ func TestInstancesEditCmdRun(t *testing.T) {
isErr: false,
},
{
name: "instances edit api.instill.tech --oauth2 bar1 --client-secret bar2 --client-id bar3",
name: "instance edit api.instill.tech --oauth2 bar1 --client-secret bar2 --client-id bar3",
input: &EditOptions{
Config: config.ConfigStub{},
InstanceOptions: InstanceOptions{
Expand All @@ -147,7 +147,7 @@ func TestInstancesEditCmdRun(t *testing.T) {
isErr: false,
},
{
name: "instances edit api.instill.tech --no-auth",
name: "instance edit api.instill.tech --no-auth",
input: &EditOptions{
Config: config.ConfigStub{},
InstanceOptions: InstanceOptions{
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/instances/instances.go → pkg/cmd/instance/instances.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"github.com/spf13/cobra"
Expand All @@ -20,9 +20,9 @@ type InstanceOptions = struct {

func New(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "instances <command>",
Short: "Instances management",
Long: `Manage instances of Instill AI, both Cloud and Core.`,
Use: "instance <command>",
Short: "Instance management",
Long: `Manage instance of Instill AI, both Cloud and Core.`,
}

cmdutil.DisableAuthCheck(cmd)
Expand All @@ -36,7 +36,7 @@ func New(f *cmdutil.Factory) *cobra.Command {
return cmd
}

// AddInstanceFlags adds common instances parameters, shared between commands.
// AddInstanceFlags adds common instance parameters, shared between commands.
func AddInstanceFlags(cmd *cobra.Command, opts *InstanceOptions) {
defs := config.DefaultHostConfig()
cmd.Flags().StringVarP(&opts.APIVersion, "api-version", "a", defs.APIVersion, "API version")
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/instances/list.go → pkg/cmd/instance/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"fmt"
Expand Down Expand Up @@ -26,13 +26,13 @@ func NewListCmd(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
cmd := &cobra.Command{
Use: "list",
Args: cobra.ExactArgs(0),
Short: "View added instances",
Short: "View added instance",
Long: heredoc.Docf(`
View added cloud and local instances.
View added cloud and local instance.
`),
Example: heredoc.Doc(`
# list instances
$ inst instances list
# list instance
$ inst instance list
`),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
Expand Down Expand Up @@ -77,7 +77,7 @@ func runList(opts *ListOptions) error {
md := cmdutil.GenTable(cols, data)
err = cmdutil.PrintMarkdown(opts.IO, md)
if err != nil {
return fmt.Errorf("ERROR: failed to list instances: %w", err)
return fmt.Errorf("ERROR: failed to list instance: %w", err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"bytes"
Expand All @@ -12,7 +12,7 @@ import (
"github.com/instill-ai/cli/pkg/iostreams"
)

func TestInstancesListCmd(t *testing.T) {
func TestInstanceListCmd(t *testing.T) {
tests := []struct {
name string
stdin string
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestInstancesListCmd(t *testing.T) {
}
}

func TestInstancesListCmdRun(t *testing.T) {
func TestInstanceListCmdRun(t *testing.T) {
tests := []struct {
name string
input *ListOptions
Expand All @@ -80,7 +80,7 @@ func TestInstancesListCmdRun(t *testing.T) {
expectFn func(*testing.T, config.Config)
}{
{
name: "instances list",
name: "instance list",
input: &ListOptions{
Config: config.ConfigStub{},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/instances/remove.go → pkg/cmd/instance/remove.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"fmt"
Expand Down Expand Up @@ -29,7 +29,7 @@ func NewRemoveCmd(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Co
Use: "remove",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instances remove API_HOSTNAME")
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instance remove API_HOSTNAME")
}
if err := instance.HostnameValidator(args[0]); err != nil {
return fmt.Errorf("error parsing API hostname %w", err)
Expand All @@ -42,7 +42,7 @@ func NewRemoveCmd(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Co
`),
Example: heredoc.Doc(`
# remove the local instance instance
$ inst instances remove instill.localhost
$ inst instance remove instill.localhost
`),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"bytes"
Expand All @@ -12,7 +12,7 @@ import (
"github.com/instill-ai/cli/pkg/iostreams"
)

func TestInstancesRemoveCmd(t *testing.T) {
func TestInstanceRemoveCmd(t *testing.T) {
tests := []struct {
name string
stdin string
Expand All @@ -28,7 +28,7 @@ func TestInstancesRemoveCmd(t *testing.T) {
isErr: true,
},
{
name: "instances remove api.instill.tech",
name: "instance remove api.instill.tech",
input: "api.instill.tech",
output: RemoveOptions{
APIHostname: "api.instill.tech",
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestInstancesRemoveCmd(t *testing.T) {
}
}

func TestInstancesRemoveCmdRun(t *testing.T) {
func TestInstanceRemoveCmdRun(t *testing.T) {
tests := []struct {
name string
input *RemoveOptions
Expand All @@ -96,7 +96,7 @@ func TestInstancesRemoveCmdRun(t *testing.T) {
expectFn func(*testing.T, config.Config)
}{
{
name: "instances remove api.instill.tech",
name: "instance remove api.instill.tech",
input: &RemoveOptions{
APIHostname: "api.instill.tech",
Config: config.ConfigStub{},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instances
package instance

import (
"fmt"
Expand Down Expand Up @@ -29,7 +29,7 @@ func NewSetDefaultCmd(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *
Use: "set-default",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instances set-default API_HOSTNAME")
return fmt.Errorf("ERROR: specify an API hostname\n$ inst instance set-default API_HOSTNAME")
}
if err := instance.HostnameValidator(args[0]); err != nil {
return fmt.Errorf("error parsing API hostname %w", err)
Expand All @@ -43,7 +43,7 @@ func NewSetDefaultCmd(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *
`),
Example: heredoc.Doc(`
# make instill.localhost the default instance
$ inst instances set-default instill.localhost
$ inst instance set-default instill.localhost
`),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
Expand Down
Loading

0 comments on commit 23f8586

Please sign in to comment.