Skip to content

Commit

Permalink
feat: add cluster option (#231)
Browse files Browse the repository at this point in the history
* feat: add cluster option

* allow back when specified cluster

* update readme
  • Loading branch information
keidarcy authored May 21, 2024
1 parent cd72ea6 commit fa062a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Usage:
e1s [flags]
Flags:
--cluster string specify the default cluster
-c, --config-file string config file (default "$HOME/.config/e1s/config.yml")
-d, --debug sets debug mode
-h, --help help for e1s
Expand Down Expand Up @@ -176,7 +177,8 @@ tail -f /tmp/e1s.log
<details>
<summary>features</summary>

- [x] config file
- [x] Specify config file
- [x] Specify the default cluster
- [x] Read only mode
- [x] Auto refresh
- [x] Describe clusters
Expand Down
3 changes: 3 additions & 0 deletions cmd/e1s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func init() {
rootCmd.Flags().String("profile", "", "specify the AWS profile")
rootCmd.Flags().String("region", "", "specify the AWS region")
rootCmd.Flags().String("theme", "", "specify color theme")
rootCmd.Flags().String("cluster", "", "specify the default cluster")

err := viper.BindPFlags(rootCmd.Flags())
if err != nil {
Expand Down Expand Up @@ -92,6 +93,7 @@ Check https://github.com/keidarcy/e1s for more details.`,
refresh := viper.GetInt("refresh")
shell := viper.GetString("shell")
theme := viper.GetString("theme")
cluster := viper.GetString("cluster")

option := e1s.Option{
ConfigFile: configFile,
Expand All @@ -102,6 +104,7 @@ Check https://github.com/keidarcy/e1s for more details.`,
Refresh: refresh,
Shell: shell,
Theme: theme,
Cluster: cluster,
}

if err := e1s.Start(option); err != nil {
Expand Down
25 changes: 22 additions & 3 deletions internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Option struct {
ConfigFile string
// Here for help view
Theme string
// Default cluster name
Cluster string
}

// tview App
Expand Down Expand Up @@ -117,10 +119,12 @@ func newApp(option Option) (*App, error) {
profile: store.Profile,
Entity: Entity{
cluster: &types.Cluster{
ClusterName: aws.String("no cluster"),
ClusterName: aws.String("e1s_default_cluster"),
ClusterArn: aws.String("e1s_default_cluster_arn"),
},
service: &types.Service{
ServiceName: aws.String("no service"),
ServiceName: aws.String("e1s_default_service"),
ServiceArn: aws.String("e1s_default_service arn"),
},
task: &types.Task{},
container: &types.Container{},
Expand Down Expand Up @@ -200,6 +204,15 @@ func (app *App) back() {

slog.Debug("app.Pages navigation", "action", "back", "pageName", pageName, "app", app)

if prevKind == ClusterKind && app.Option.Cluster != "" {
app.Option.Cluster = ""
err := app.showPrimaryKindPage(ClusterKind, false)
if err != nil {
app.Notice.Warn("failed to back to cluster list")
}
return
}

app.Pages.SwitchToPage(pageName)
}

Expand All @@ -222,7 +235,13 @@ func (app *App) getPageHandle() string {
}

func (app *App) start() error {
err := app.showPrimaryKindPage(ClusterKind, false)
var err error
if app.Option.Cluster == "" {
err = app.showPrimaryKindPage(ClusterKind, false)
} else {
app.cluster.ClusterName = &app.Option.Cluster
err = app.showPrimaryKindPage(ServiceKind, false)
}

if app.Option.Refresh > 0 {
slog.Debug("Auto refresh rate", "seconds", app.Option.Refresh)
Expand Down
1 change: 1 addition & 0 deletions internal/view/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (app *App) showHelpPage() {
{key: "shell", description: app.Option.Shell},
{key: "refresh", description: strconv.Itoa(app.Option.Refresh)},
{key: "theme", description: app.Option.Theme},
{key: "cluster", description: app.Option.Cluster},
})
flex := tview.NewFlex().
AddItem(resource, 0, 1, false).
Expand Down

0 comments on commit fa062a4

Please sign in to comment.