Skip to content

Commit

Permalink
Merge pull request #1585 from rsteube/systemctl-user-manager
Browse files Browse the repository at this point in the history
systemctl user manager
  • Loading branch information
rsteube authored Mar 22, 2023
2 parents 63909f6 + b2009af commit 6a6a3db
Show file tree
Hide file tree
Showing 57 changed files with 285 additions and 159 deletions.
38 changes: 38 additions & 0 deletions completers/systemctl_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package action

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/systemctl"
"github.com/spf13/cobra"
)

func userFlag(cmd *cobra.Command) bool {
if flag := cmd.Root().Flag("user"); flag != nil && flag.Changed {
return true
}
return false
}

func ActionProperties(cmd *cobra.Command, units ...string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return systemctl.ActionProperties(systemctl.PropertiesOpts{User: userFlag(cmd), Units: units})
})
}

func ActionServices(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return systemctl.ActionServices(userFlag(cmd))
})
}

func ActionTargets(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return systemctl.ActionTargets(userFlag(cmd))
})
}

func ActionUnits(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return systemctl.ActionUnits(userFlag(cmd))
})
}
18 changes: 0 additions & 18 deletions completers/systemctl_completer/cmd/action/environment.go

This file was deleted.

10 changes: 0 additions & 10 deletions completers/systemctl_completer/cmd/action/log.go

This file was deleted.

24 changes: 0 additions & 24 deletions completers/systemctl_completer/cmd/action/service.go

This file was deleted.

24 changes: 0 additions & 24 deletions completers/systemctl_completer/cmd/action/target.go

This file was deleted.

23 changes: 0 additions & 23 deletions completers/systemctl_completer/cmd/action/unit.go

This file was deleted.

4 changes: 2 additions & 2 deletions completers/systemctl_completer/cmd/addRequires.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func init() {
rootCmd.AddCommand(addRequiresCmd)

carapace.Gen(addRequiresCmd).PositionalCompletion(
action.ActionTargets(),
action.ActionTargets(addRequiresCmd),
)

carapace.Gen(addRequiresCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(addRequiresCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
4 changes: 2 additions & 2 deletions completers/systemctl_completer/cmd/addWants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func init() {
rootCmd.AddCommand(addWantsCmd)

carapace.Gen(addWantsCmd).PositionalCompletion(
action.ActionTargets(),
action.ActionTargets(addWantsCmd),
)

carapace.Gen(addWantsCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(addWantsCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
rootCmd.AddCommand(bindCmd)

carapace.Gen(bindCmd).PositionalCompletion(
action.ActionUnits(),
action.ActionUnits(bindCmd),
carapace.ActionFiles(),
carapace.ActionFiles(),
)
Expand Down
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(catCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(catCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(cleanCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(cleanCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(disableCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(disableCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(editCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(editCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
carapace.Gen(enableCmd).PositionalAnyCompletion(
carapace.Batch(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(enableCmd).Invoke(c).Filter(c.Args).ToA()
}),
carapace.ActionFiles(),
).ToA(),
Expand Down
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(freezeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(freezeCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
carapace.Gen(helpCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
action.ActionUnits(),
action.ActionUnits(helpCmd),
ps.ActionProcessIds(),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
Expand Down
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/isActive.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(isActiveCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(isActiveCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/isEnabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(isEnabledCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(isEnabledCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/isFailed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(isFailedCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(isFailedCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/isolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
rootCmd.AddCommand(isolateCmd)

carapace.Gen(isolateCmd).PositionalCompletion(
action.ActionUnits(),
action.ActionUnits(isolateCmd),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(killCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(killCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(linkCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(linkCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/listDependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(listDependenciesCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(listDependenciesCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/listSockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(listSocketsCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(listSocketsCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/listTimers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(listTimersCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(listTimersCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/listUnits.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(listUnitsCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(listUnitsCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
4 changes: 2 additions & 2 deletions completers/systemctl_completer/cmd/logLevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/systemctl_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/systemctl"
"github.com/spf13/cobra"
)

Expand All @@ -18,6 +18,6 @@ func init() {
rootCmd.AddCommand(logLevelCmd)

carapace.Gen(logLevelCmd).PositionalCompletion(
action.ActionLogLevels(),
systemctl.ActionLogLevels(),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/logTarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
rootCmd.AddCommand(logTargetCmd)

carapace.Gen(logTargetCmd).PositionalCompletion(
action.ActionTargets(),
action.ActionTargets(logTargetCmd),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(maskCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(maskCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(presetCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(presetCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/reenable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(reenableCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(reenableCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/systemctl_completer/cmd/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

carapace.Gen(reloadCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionUnits().Invoke(c).Filter(c.Args).ToA()
return action.ActionUnits(reloadCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
Loading

0 comments on commit 6a6a3db

Please sign in to comment.