mirror of
https://gitea.elkins.co/Networking/ccl.git
synced 2025-03-09 12:41:40 -05:00
Mask disabled category from action by default
This commit is contained in:
parent
98ec553778
commit
ddd391c8b0
@ -37,7 +37,7 @@ var createCmd = &cobra.Command{
|
||||
Long: `Create containers specified by the arguments. Arguments can be either container
|
||||
names or categories. Multiple arguments are supported.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "CREATE", cont.Name)
|
||||
for _, c := range cont.CreateCommands() {
|
||||
|
@ -43,7 +43,7 @@ ccl ls all # same as above
|
||||
ccl ls default sub # multiple ok
|
||||
ccl ls squid`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
|
||||
defer w.Flush()
|
||||
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
|
||||
func validNouns(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
|
||||
validArgs := []string{}
|
||||
for _, c := range config.Union([]string{}) {
|
||||
for _, c := range config.Containers {
|
||||
validArgs = append(validArgs, c.Name)
|
||||
}
|
||||
validArgs = append(validArgs, config.Categories()...)
|
||||
|
@ -38,7 +38,7 @@ var pullCmd = &cobra.Command{
|
||||
affected: the old image will still remain, though untagged, and any defined containers
|
||||
will still use it.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "PULL", cont.Name)
|
||||
for _, cmd := range cont.PullCommands() {
|
||||
|
@ -37,7 +37,7 @@ var recreateCmd = &cobra.Command{
|
||||
Long: `Recreate container images, stopping and restarting if necessary. Arguments can be
|
||||
one or more container names or categories. If empty, "all" is assumed.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "RECREATE", cont.Name)
|
||||
for _, c := range cont.RecreateCommands() {
|
||||
|
@ -37,7 +37,7 @@ var restartCmd = &cobra.Command{
|
||||
Long: `Stop configured containers (if running), then restart them. Arguments can be
|
||||
one or more container names or categories. If empty, "all" is assumed.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "RESTART", cont.Name)
|
||||
for _, c := range cont.RestartCommands() {
|
||||
|
@ -38,7 +38,7 @@ var rmCmd = &cobra.Command{
|
||||
Long: `Remove defined containers or categories if they have been created.
|
||||
If running, they will first be stopped.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "REMOVE", cont.Name)
|
||||
for _, cmd := range cont.DestroyCommands() {
|
||||
|
10
cmd/root.go
10
cmd/root.go
@ -42,6 +42,13 @@ to define, start, stop, or update the container images. Configuration is read
|
||||
from a toml configuration file, and the utility uses this information to
|
||||
execute the necessary podman commands.`,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
PersistentPreRun: func(*cobra.Command, []string) {
|
||||
if incDisabled {
|
||||
contMask = []string{}
|
||||
} else {
|
||||
contMask = []string{"disabled"}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
@ -49,6 +56,8 @@ var (
|
||||
verbose bool
|
||||
fake bool
|
||||
socket string
|
||||
incDisabled bool
|
||||
contMask []string
|
||||
)
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
@ -82,5 +91,6 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&config.ConfigFile, "config", "c", config.CONFIG_FILE_DEFAULT, "pathname of config file")
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show additional info from command execution")
|
||||
rootCmd.PersistentFlags().BoolVarP(&fake, "no-action", "n", false, "do not actually execute commands")
|
||||
rootCmd.PersistentFlags().BoolVarP(&incDisabled, "include-disabled", "a", false, "include category=disabled containers in actions")
|
||||
rootCmd.PersistentFlags().StringVarP(&socket, "socket", "k", "unix:///run/podman/podman.sock", "socket address to which to connect")
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ to use as a ccl config file.`,
|
||||
Containers []container.Container
|
||||
}
|
||||
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
output, err := toml.Marshal(parse{conts})
|
||||
if err != nil {
|
||||
fmt.Println("could not marshal containers:", err)
|
||||
|
@ -37,7 +37,7 @@ var startCmd = &cobra.Command{
|
||||
Long: `Start configured containers. They must be created first. Arguments can be
|
||||
one or more container names or categories. If empty, "all" is assumed.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "START", cont.Name)
|
||||
for _, c := range cont.StartCommands() {
|
||||
|
@ -37,7 +37,7 @@ var stopCmd = &cobra.Command{
|
||||
Long: `Stop configured containers if running. Arguments can be
|
||||
one or more container names or categories. If empty, "all" is assumed.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "STOP", cont.Name)
|
||||
for _, c := range cont.StopCommands() {
|
||||
|
@ -37,7 +37,7 @@ var updateCmd = &cobra.Command{
|
||||
Long: `Update container images, stopping and restarting if necessary. Arguments can be
|
||||
one or more container names or categories. If empty, "all" is assumed.`,
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conts := config.Union(args)
|
||||
conts := config.Union(args, contMask)
|
||||
for _, cont := range conts {
|
||||
fmt.Fprintln(output, "UPDATE", cont.Name)
|
||||
for _, c := range cont.UpdateCommands() {
|
||||
|
@ -19,7 +19,7 @@ const (
|
||||
type command string
|
||||
|
||||
var (
|
||||
ConfigFile string = CONFIG_FILE_DEFAULT
|
||||
ConfigFile = CONFIG_FILE_DEFAULT
|
||||
Networks = []network.Network{}
|
||||
Containers = []container.Container{}
|
||||
)
|
||||
@ -33,17 +33,24 @@ func Categories() []string {
|
||||
for _, c := range gs.Values() {
|
||||
categories = append(categories, c.(string))
|
||||
}
|
||||
slices.Sort(categories)
|
||||
return categories
|
||||
}
|
||||
|
||||
func Union(ids []string) (conts []container.Container) {
|
||||
func Union(ids []string, catMask []string) (conts []container.Container) {
|
||||
if len(ids) == 0 {
|
||||
return Containers
|
||||
ids = []string{"all"}
|
||||
}
|
||||
h := hashset.New()
|
||||
for _, id := range ids {
|
||||
if j := slices.Index(catMask, id); j >= 0 {
|
||||
catMask = slices.Delete(catMask, j, j+1)
|
||||
}
|
||||
for _, c := range Containers {
|
||||
if id == "all" || c.Name == id || c.Category == id {
|
||||
if (id == "all" || c.Category == id) && !slices.Contains(catMask, c.Category) {
|
||||
h.Add(c.Name)
|
||||
}
|
||||
if c.Name == id {
|
||||
h.Add(c.Name)
|
||||
}
|
||||
}
|
||||
@ -56,8 +63,17 @@ func Union(ids []string) (conts []container.Container) {
|
||||
if len(conts) == 0 {
|
||||
log.WithFields(log.Fields{
|
||||
"ids": ids,
|
||||
}).Warnln("No matching containers")
|
||||
}).Warnln("No matching containers. If disabled, try adding -a")
|
||||
}
|
||||
slices.SortFunc(conts, func(a, b container.Container) bool {
|
||||
if a.Category < b.Category {
|
||||
return true
|
||||
}
|
||||
if a.Category > b.Category {
|
||||
return false
|
||||
}
|
||||
return a.Name <= b.Name
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@ -81,5 +97,8 @@ func Init(conn context.Context) error {
|
||||
for i := range p.Containers {
|
||||
p.Containers[i].Init(conn, Networks)
|
||||
}
|
||||
slices.SortFunc(Containers, func(a, b container.Container) bool {
|
||||
return a.Name < b.Name
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user