Skip to content

Commit

Permalink
Merge pull request #3944 from apostasie/refactor-cleanup-1
Browse files Browse the repository at this point in the history
Cleanup/refactor proposal
  • Loading branch information
AkihiroSuda authored Mar 3, 2025
2 parents 4c8e2f8 + e21e4b2 commit 892a8bb
Show file tree
Hide file tree
Showing 99 changed files with 431 additions and 431 deletions.
6 changes: 3 additions & 3 deletions cmd/nerdctl/apparmor/apparmor_inspect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ import (
"github.com/containerd/nerdctl/v2/pkg/defaults"
)

func newApparmorInspectCommand() *cobra.Command {
func inspectCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "inspect",
Short: fmt.Sprintf("Display the default AppArmor profile %q. Other profiles cannot be displayed with this command.", defaults.AppArmorProfileName),
Args: cobra.NoArgs,
RunE: apparmorInspectAction,
RunE: inspectAction,
SilenceUsage: true,
SilenceErrors: true,
}
return cmd
}

func apparmorInspectAction(cmd *cobra.Command, args []string) error {
func inspectAction(cmd *cobra.Command, args []string) error {
return apparmor.Inspect(types.ApparmorInspectOptions{
Stdout: cmd.OutOrStdout(),
})
Expand Down
10 changes: 5 additions & 5 deletions cmd/nerdctl/apparmor/apparmor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
)

func NewApparmorCommand() *cobra.Command {
func Command() *cobra.Command {
cmd := &cobra.Command{
Annotations: map[string]string{helpers.Category: helpers.Management},
Use: "apparmor",
Expand All @@ -32,10 +32,10 @@ func NewApparmorCommand() *cobra.Command {
SilenceErrors: true,
}
cmd.AddCommand(
newApparmorLsCommand(),
newApparmorInspectCommand(),
newApparmorLoadCommand(),
newApparmorUnloadCommand(),
listCommand(),
inspectCommand(),
loadCommand(),
unloadCommand(),
)
return cmd
}
10 changes: 5 additions & 5 deletions cmd/nerdctl/apparmor/apparmor_list_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"github.com/containerd/nerdctl/v2/pkg/cmd/apparmor"
)

func newApparmorLsCommand() *cobra.Command {
func listCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ls",
Aliases: []string{"list"},
Short: "List the loaded AppArmor profiles",
Args: cobra.NoArgs,
RunE: apparmorLsAction,
RunE: listAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -42,7 +42,7 @@ func newApparmorLsCommand() *cobra.Command {
return cmd
}

func processApparmorListOptions(cmd *cobra.Command) (types.ApparmorListOptions, error) {
func listOptions(cmd *cobra.Command) (types.ApparmorListOptions, error) {
quiet, err := cmd.Flags().GetBool("quiet")
if err != nil {
return types.ApparmorListOptions{}, err
Expand All @@ -58,8 +58,8 @@ func processApparmorListOptions(cmd *cobra.Command) (types.ApparmorListOptions,
}, nil
}

func apparmorLsAction(cmd *cobra.Command, args []string) error {
options, err := processApparmorListOptions(cmd)
func listAction(cmd *cobra.Command, args []string) error {
options, err := listOptions(cmd)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/nerdctl/apparmor/apparmor_load_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import (
"github.com/containerd/nerdctl/v2/pkg/defaults"
)

func newApparmorLoadCommand() *cobra.Command {
func loadCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "load",
Short: fmt.Sprintf("Load the default AppArmor profile %q. Requires root.", defaults.AppArmorProfileName),
Args: cobra.NoArgs,
RunE: apparmorLoadAction,
RunE: loadAction,
SilenceUsage: true,
SilenceErrors: true,
}
return cmd
}

func apparmorLoadAction(cmd *cobra.Command, args []string) error {
func loadAction(cmd *cobra.Command, args []string) error {
return apparmor.Load()
}
10 changes: 5 additions & 5 deletions cmd/nerdctl/apparmor/apparmor_unload_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ import (
"github.com/containerd/nerdctl/v2/pkg/defaults"
)

func newApparmorUnloadCommand() *cobra.Command {
func unloadCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "unload [PROFILE]",
Short: fmt.Sprintf("Unload an AppArmor profile. The target profile name defaults to %q. Requires root.", defaults.AppArmorProfileName),
Args: cobra.MaximumNArgs(1),
RunE: apparmorUnloadAction,
ValidArgsFunction: apparmorUnloadShellComplete,
RunE: unloadAction,
ValidArgsFunction: unloadShellComplete,
SilenceUsage: true,
SilenceErrors: true,
}
return cmd
}

func apparmorUnloadAction(cmd *cobra.Command, args []string) error {
func unloadAction(cmd *cobra.Command, args []string) error {
target := defaults.AppArmorProfileName
if len(args) > 0 {
target = args[0]
}
return apparmor.Unload(target)
}

func apparmorUnloadShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func unloadShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completion.ApparmorProfiles(cmd)
}
24 changes: 12 additions & 12 deletions cmd/nerdctl/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/containerd/nerdctl/v2/pkg/cmd/builder"
)

func NewBuilderCommand() *cobra.Command {
func Command() *cobra.Command {
var cmd = &cobra.Command{
Annotations: map[string]string{helpers.Category: helpers.Management},
Use: "builder",
Expand All @@ -40,20 +40,20 @@ func NewBuilderCommand() *cobra.Command {
SilenceErrors: true,
}
cmd.AddCommand(
NewBuildCommand(),
newBuilderPruneCommand(),
newBuilderDebugCommand(),
BuildCommand(),
pruneCommand(),
debugCommand(),
)
return cmd
}

func newBuilderPruneCommand() *cobra.Command {
func pruneCommand() *cobra.Command {
shortHelp := `Clean up BuildKit build cache`
var cmd = &cobra.Command{
Use: "prune",
Args: cobra.NoArgs,
Short: shortHelp,
RunE: builderPruneAction,
RunE: pruneAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -65,8 +65,8 @@ func newBuilderPruneCommand() *cobra.Command {
return cmd
}

func builderPruneAction(cmd *cobra.Command, _ []string) error {
options, err := processBuilderPruneOptions(cmd)
func pruneAction(cmd *cobra.Command, _ []string) error {
options, err := pruneOptions(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func builderPruneAction(cmd *cobra.Command, _ []string) error {
return nil
}

func processBuilderPruneOptions(cmd *cobra.Command) (types.BuilderPruneOptions, error) {
func pruneOptions(cmd *cobra.Command) (types.BuilderPruneOptions, error) {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return types.BuilderPruneOptions{}, err
Expand Down Expand Up @@ -131,13 +131,13 @@ func processBuilderPruneOptions(cmd *cobra.Command) (types.BuilderPruneOptions,
}, nil
}

func newBuilderDebugCommand() *cobra.Command {
func debugCommand() *cobra.Command {
shortHelp := `Debug Dockerfile`
var cmd = &cobra.Command{
Use: "debug",
Short: shortHelp,
PreRunE: helpers.CheckExperimental("`nerdctl builder debug`"),
RunE: builderDebugAction,
RunE: debugAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -150,7 +150,7 @@ func newBuilderDebugCommand() *cobra.Command {
return cmd
}

func builderDebugAction(cmd *cobra.Command, args []string) error {
func debugAction(cmd *cobra.Command, args []string) error {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/builder/builder_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/containerd/nerdctl/v2/pkg/strutil"
)

func NewBuildCommand() *cobra.Command {
func BuildCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "build [flags] PATH",
Short: "Build an image from a Dockerfile. Needs buildkitd to be running.",
Expand Down
48 changes: 24 additions & 24 deletions cmd/nerdctl/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/containerd/nerdctl/v2/pkg/composer"
)

func NewComposeCommand() *cobra.Command {
func Command() *cobra.Command {
var cmd = &cobra.Command{
Use: "compose [flags] COMMAND",
Short: "Compose",
Expand All @@ -41,29 +41,29 @@ func NewComposeCommand() *cobra.Command {
cmd.PersistentFlags().StringArray("profile", []string{}, "Specify a profile to enable")

cmd.AddCommand(
newComposeUpCommand(),
newComposeLogsCommand(),
newComposeConfigCommand(),
newComposeCopyCommand(),
newComposeBuildCommand(),
newComposeExecCommand(),
newComposeImagesCommand(),
newComposePortCommand(),
newComposePushCommand(),
newComposePullCommand(),
newComposeDownCommand(),
newComposePsCommand(),
newComposeKillCommand(),
newComposeRestartCommand(),
newComposeRemoveCommand(),
newComposeRunCommand(),
newComposeVersionCommand(),
newComposeStartCommand(),
newComposeStopCommand(),
newComposePauseCommand(),
newComposeUnpauseCommand(),
newComposeTopCommand(),
newComposeCreateCommand(),
upCommand(),
logsCommand(),
configCommand(),
copyCommand(),
buildCommand(),
execCommand(),
imagesCommand(),
portCommand(),
pushCommand(),
pullCommand(),
downCommand(),
psCommand(),
killCommand(),
restartCommand(),
removeCommand(),
runCommand(),
versionCommand(),
startCommand(),
stopCommand(),
pauseCommand(),
unpauseCommand(),
topCommand(),
createCommand(),
)

return cmd
Expand Down
6 changes: 3 additions & 3 deletions cmd/nerdctl/compose/compose_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"github.com/containerd/nerdctl/v2/pkg/composer"
)

func newComposeBuildCommand() *cobra.Command {
func buildCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "build [flags] [SERVICE...]",
Short: "Build or rebuild services",
RunE: composeBuildAction,
RunE: buildAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -40,7 +40,7 @@ func newComposeBuildCommand() *cobra.Command {
return cmd
}

func composeBuildAction(cmd *cobra.Command, args []string) error {
func buildAction(cmd *cobra.Command, args []string) error {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/nerdctl/compose/compose_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/containerd/nerdctl/v2/pkg/composer"
)

func newComposeConfigCommand() *cobra.Command {
func configCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "config",
Short: "Validate and view the Compose file",
RunE: composeConfigAction,
RunE: configAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -45,7 +45,7 @@ func newComposeConfigCommand() *cobra.Command {
return cmd
}

func composeConfigAction(cmd *cobra.Command, args []string) error {
func configAction(cmd *cobra.Command, args []string) error {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/nerdctl/compose/compose_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import (
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
)

func newComposeCopyCommand() *cobra.Command {
func copyCommand() *cobra.Command {
usage := `cp [OPTIONS] SERVICE:SRC_PATH DEST_PATH|-
nerdctl compose cp [OPTIONS] SRC_PATH|- SERVICE:DEST_PATH`
var cmd = &cobra.Command{
Use: usage,
Short: "Copy files/folders between a service container and the local filesystem",
Args: cobra.ExactArgs(2),
RunE: composeCopyAction,
RunE: copyAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -45,7 +45,7 @@ func newComposeCopyCommand() *cobra.Command {
return cmd
}

func composeCopyAction(cmd *cobra.Command, args []string) error {
func copyAction(cmd *cobra.Command, args []string) error {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/nerdctl/compose/compose_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/containerd/nerdctl/v2/pkg/composer"
)

func newComposeCreateCommand() *cobra.Command {
func createCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "create [flags] [SERVICE...]",
Short: "Creates containers for one or more services",
RunE: composeCreateAction,
RunE: createAction,
SilenceUsage: true,
SilenceErrors: true,
}
Expand All @@ -43,7 +43,7 @@ func newComposeCreateCommand() *cobra.Command {
return cmd
}

func composeCreateAction(cmd *cobra.Command, args []string) error {
func createAction(cmd *cobra.Command, args []string) error {
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 892a8bb

Please sign in to comment.