Skip to content

Commit

Permalink
fix: fix per pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme committed Apr 27, 2022
1 parent d82935b commit caed0af
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 44 deletions.
23 changes: 10 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,27 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
22 changes: 11 additions & 11 deletions pkg/cmd/chat/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"github.com/spf13/cobra"
)

func NewChannelCmds() []*cobra.Command {
func NewCmds() []*cobra.Command {
return []*cobra.Command{
getChannelCmd(),
createChannelCmd(),
deleteChannelCmd(),
updateChannelCmd(),
listChannelsCmd()}
getCmd(),
createCmd(),
deleteCmd(),
updateCmd(),
listCmd()}
}

func getChannelCmd() *cobra.Command {
func getCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get-channel --type [channel-type] --id [channel-id]",
Short: "Returns a channel",
Expand Down Expand Up @@ -64,7 +64,7 @@ func getChannelCmd() *cobra.Command {
return cmd
}

func createChannelCmd() *cobra.Command {
func createCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-channel --type [channel-type] --id [channel-id]",
Short: "Creates a channel",
Expand Down Expand Up @@ -104,7 +104,7 @@ func createChannelCmd() *cobra.Command {
return cmd
}

func deleteChannelCmd() *cobra.Command {
func deleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-channel --type [channel-type] --id [channel-id]",
Short: "Deletes a channel",
Expand Down Expand Up @@ -143,7 +143,7 @@ func deleteChannelCmd() *cobra.Command {
return cmd
}

func updateChannelCmd() *cobra.Command {
func updateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-channel --type [channel-type] --id [channel-id]",
Short: "Updates a channel",
Expand Down Expand Up @@ -183,7 +183,7 @@ func updateChannelCmd() *cobra.Command {
return cmd
}

func listChannelsCmd() *cobra.Command {
func listCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list-channels --type [channel-type]",
Short: "Lists channels",
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/chat/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestCreateChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.RandomString(10)
t.Cleanup(func() {
test.DeleteChannel(ch)
Expand All @@ -30,7 +30,7 @@ func TestCreateChannel(t *testing.T) {
}

func TestCreateChannelAlreadyExists(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
t.Cleanup(func() {
test.DeleteChannel(ch)
Expand All @@ -44,7 +44,7 @@ func TestCreateChannelAlreadyExists(t *testing.T) {
}

func TestGetChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
t.Cleanup(func() {
test.DeleteChannel(ch)
Expand All @@ -57,7 +57,7 @@ func TestGetChannel(t *testing.T) {
}

func TestDeleteChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
cmd.SetArgs([]string{"delete-channel", "-t", "messaging", "-i", ch, "--hard"})
_, err := cmd.ExecuteC()
Expand All @@ -70,7 +70,7 @@ func TestDeleteChannel(t *testing.T) {
}

func TestUpdateChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
t.Cleanup(func() {
test.DeleteChannel(ch)
Expand All @@ -88,7 +88,7 @@ func TestUpdateChannel(t *testing.T) {
}

func TestListChannel(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewChannelCmds()...)
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
cmd.SetArgs([]string{"list-channels", "-t", "messaging", "-l", "1"})
_, err := cmd.ExecuteC()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/chat/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/spf13/cobra"
)

func NewChatRootCmd() *cobra.Command {
func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "chat",
Short: "Interact with your Stream Chat application",
}

cmd.AddCommand(watch.NewWatchCmd())
cmd.AddCommand(channel.NewChannelCmds()...)
cmd.AddCommand(watch.NewCmd())
cmd.AddCommand(channel.NewCmds()...)

return cmd
}
2 changes: 1 addition & 1 deletion pkg/cmd/chat/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

func NewWatchCmd() *cobra.Command {
func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "watch [task-id]",
Short: "Waits for an async task to complete",
Expand Down
19 changes: 13 additions & 6 deletions pkg/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

func NewRootConfigCmd() *cobra.Command {
func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Manage app configurations",
Expand All @@ -26,6 +26,7 @@ func newAppCmd() *cobra.Command {
Use: "new",
Short: "Add a new application",
Long: "Add a new application which can be used for further operations",

RunE: func(cmd *cobra.Command, args []string) error {
return runQuestionnaire(cmd)
},
Expand All @@ -34,13 +35,19 @@ func newAppCmd() *cobra.Command {

func removeAppCmd() *cobra.Command {
return &cobra.Command{
Use: "remove [app-name]",
Short: "Remove an application. This operation is irrevocable",
Args: cobra.ExactArgs(1),
Use: "remove [app-name-1] [app-name-2] ...",
Short: "Remove 1 or more application. This operation is irrevocable",
Args: cobra.MinimumNArgs(1),

RunE: func(cmd *cobra.Command, args []string) error {
config := cfg.GetConfig(cmd)
return config.Remove(args[0])
for _, appName := range args {
if err := config.Remove(appName); err != nil {
return err
}
}

return nil
},
}
}
Expand All @@ -53,7 +60,7 @@ func listAppsCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
t := tabby.NewCustom(w)
t.AddHeader("", "Name", "Access Key", "Secret Key", "Url")
t.AddHeader("", "Name", "Access Key", "Secret Key", "URL")

config := cfg.GetConfig(cmd)

Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func NewRootCmd() *cobra.Command {
}

fl := root.PersistentFlags()
fl.String("app", "", "[optional] Application id to use as it's defined in the configuration file")
fl.String("app", "", "[optional] Application name to use as it's defined in the configuration file")
fl.StringVar(cfgPath, "config", "", "[optional] Explicit config file path")

root.AddCommand(
cfgCmd.NewRootConfigCmd(),
chat.NewChatRootCmd(),
cfgCmd.NewRootCmd(),
chat.NewRootCmd(),
)

cobra.OnInitialize(config.GetInitConfig(root, cfgPath))
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func GetInitConfig(cmd *cobra.Command, cfgPath *string) func() {
}

viper.SetConfigFile(configPath)
viper.SetConfigType("yaml")

err := viper.ReadInConfig()
if err != nil && os.IsNotExist(err) {
Expand Down

0 comments on commit caed0af

Please sign in to comment.