Skip to content

Commit

Permalink
feat #207: added flag and env to hide disabled tui processes
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Aug 9, 2024
1 parent 5b0607f commit 842083c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/cmd/project_runner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/f1bonacc1/process-compose/src/admitter"
"github.com/f1bonacc1/process-compose/src/app"
"github.com/f1bonacc1/process-compose/src/config"
"github.com/f1bonacc1/process-compose/src/loader"
Expand All @@ -13,9 +12,6 @@ import (
)

func getProjectRunner(process []string, noDeps bool, mainProcess string, mainProcessArgs []string) *app.ProjectRunner {
if *pcFlags.HideDisabled {
opts.AddAdmitter(&admitter.DisabledProcAdmitter{})
}
if *pcFlags.DisableDotEnv {
opts.DisableDotenv()
}
Expand Down Expand Up @@ -93,6 +89,7 @@ func startTui(runner app.IProject) {
tui.WithRefreshRate(*pcFlags.RefreshRate),
tui.WithReadOnlyMode(*pcFlags.IsReadOnlyMode),
tui.WithFullScreen(*pcFlags.IsTuiFullScreen),
tui.WithDisabledHidden(*pcFlags.HideDisabled),
}
if !*pcFlags.IsReadOnlyMode {
config.CreateProcCompHome()
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func init() {
rootCmd.Flags().BoolVar(pcFlags.KeepProjectOn, "keep-project", *pcFlags.KeepProjectOn, "keep the project running even after all processes exit")
rootCmd.PersistentFlags().BoolVar(pcFlags.NoServer, "no-server", *pcFlags.NoServer, "disable HTTP server (env: "+config.EnvVarNameNoServer+")")
rootCmd.PersistentFlags().BoolVar(pcFlags.IsOrderedShutDown, "ordered-shutdown", *pcFlags.IsOrderedShutDown, "shut down processes in reverse dependency order")
rootCmd.Flags().BoolVarP(pcFlags.HideDisabled, "hide-disabled", "d", *pcFlags.HideDisabled, "hide disabled processes")
rootCmd.Flags().BoolVarP(pcFlags.HideDisabled, "hide-disabled", "d", *pcFlags.HideDisabled, "hide disabled processes (env: "+config.EnvVarHideDisabled+")")
rootCmd.Flags().VarP(refreshRateFlag{pcFlags.RefreshRate}, "ref-rate", "r", "TUI refresh rate in seconds or as a Go duration string (e.g. 1s)")
rootCmd.PersistentFlags().IntVarP(pcFlags.PortNum, "port", "p", *pcFlags.PortNum, "port number (env: "+config.EnvVarNamePort+")")
rootCmd.Flags().StringArrayVarP(&opts.FileNames, "config", "f", config.GetConfigDefault(), "path to config files to load (env: "+config.EnvVarNameConfig+")")
Expand Down
3 changes: 2 additions & 1 deletion src/config/Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
EnvVarReadOnlyMode = "PC_READ_ONLY"
EnvVarDisableDotEnv = "PC_DISABLE_DOTENV"
EnvVarTuiFullScreen = "PC_TUI_FULL_SCREEN"
EnvVarHideDisabled = "PC_HIDE_DISABLED_PROC"
)

// Flags represents PC configuration flags.
Expand Down Expand Up @@ -84,7 +85,7 @@ func NewFlags() *Flags {
LogFollow: toPtr(false),
LogTailLength: toPtr(math.MaxInt),
NoDependencies: toPtr(false),
HideDisabled: toPtr(false),
HideDisabled: toPtr(getHideDisabledDefault()),
SortColumn: toPtr(DefaultSortColumn),
IsReverseSort: toPtr(false),
NoServer: toPtr(getNoServerDefault()),
Expand Down
5 changes: 5 additions & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,8 @@ func getTuiFullScreenDefault() bool {
_, found := os.LookupEnv(EnvVarTuiFullScreen)
return found
}

func getHideDisabledDefault() bool {
_, found := os.LookupEnv(EnvVarHideDisabled)
return found
}
7 changes: 7 additions & 0 deletions src/tui/tui_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ func WithFullScreen(isFullScreen bool) Option {
return nil
}
}

func WithDisabledHidden(isHidden bool) Option {
return func(view *pcView) error {
view.hideDisabled.Store(isHidden)
return nil
}
}

0 comments on commit 842083c

Please sign in to comment.