github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose.go (about)

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"github.com/containerd/nerdctl/pkg/composer"
    21  	"github.com/spf13/cobra"
    22  )
    23  
    24  func newComposeCommand() *cobra.Command {
    25  	var composeCommand = &cobra.Command{
    26  		Use:              "compose [flags] COMMAND",
    27  		Short:            "Compose",
    28  		RunE:             unknownSubcommandAction,
    29  		SilenceUsage:     true,
    30  		SilenceErrors:    true,
    31  		TraverseChildren: true, // required for global short hands like -f
    32  	}
    33  	// `-f` is a nonPersistentAlias, as it conflicts with `nerdctl compose logs --follow`
    34  	AddPersistentStringArrayFlag(composeCommand, "file", nil, []string{"f"}, nil, "", "Specify an alternate compose file")
    35  	composeCommand.PersistentFlags().String("project-directory", "", "Specify an alternate working directory")
    36  	composeCommand.PersistentFlags().StringP("project-name", "p", "", "Specify an alternate project name")
    37  	composeCommand.PersistentFlags().String("env-file", "", "Specify an alternate environment file")
    38  	composeCommand.PersistentFlags().String("ipfs-address", "", "multiaddr of IPFS API (default uses $IPFS_PATH env variable if defined or local directory ~/.ipfs)")
    39  	composeCommand.PersistentFlags().StringArray("profile", []string{}, "Specify a profile to enable")
    40  
    41  	composeCommand.AddCommand(
    42  		newComposeUpCommand(),
    43  		newComposeLogsCommand(),
    44  		newComposeConfigCommand(),
    45  		newComposeCopyCommand(),
    46  		newComposeBuildCommand(),
    47  		newComposeExecCommand(),
    48  		newComposeImagesCommand(),
    49  		newComposePortCommand(),
    50  		newComposePushCommand(),
    51  		newComposePullCommand(),
    52  		newComposeDownCommand(),
    53  		newComposePsCommand(),
    54  		newComposeKillCommand(),
    55  		newComposeRestartCommand(),
    56  		newComposeRemoveCommand(),
    57  		newComposeRunCommand(),
    58  		newComposeVersionCommand(),
    59  		newComposeStartCommand(),
    60  		newComposeStopCommand(),
    61  		newComposePauseCommand(),
    62  		newComposeUnpauseCommand(),
    63  		newComposeTopCommand(),
    64  		newComposeCreateCommand(),
    65  	)
    66  
    67  	return composeCommand
    68  }
    69  
    70  func getComposeOptions(cmd *cobra.Command, debugFull, experimental bool) (composer.Options, error) {
    71  	nerdctlCmd, nerdctlArgs := globalFlags(cmd)
    72  	projectDirectory, err := cmd.Flags().GetString("project-directory")
    73  	if err != nil {
    74  		return composer.Options{}, err
    75  	}
    76  	envFile, err := cmd.Flags().GetString("env-file")
    77  	if err != nil {
    78  		return composer.Options{}, err
    79  	}
    80  	projectName, err := cmd.Flags().GetString("project-name")
    81  	if err != nil {
    82  		return composer.Options{}, err
    83  	}
    84  	files, err := cmd.Flags().GetStringArray("file")
    85  	if err != nil {
    86  		return composer.Options{}, err
    87  	}
    88  	ipfsAddressStr, err := cmd.Flags().GetString("ipfs-address")
    89  	if err != nil {
    90  		return composer.Options{}, err
    91  	}
    92  	profiles, err := cmd.Flags().GetStringArray("profile")
    93  	if err != nil {
    94  		return composer.Options{}, err
    95  	}
    96  
    97  	return composer.Options{
    98  		Project:          projectName,
    99  		ProjectDirectory: projectDirectory,
   100  		ConfigPaths:      files,
   101  		Profiles:         profiles,
   102  		EnvFile:          envFile,
   103  		NerdctlCmd:       nerdctlCmd,
   104  		NerdctlArgs:      nerdctlArgs,
   105  		DebugPrintFull:   debugFull,
   106  		Experimental:     experimental,
   107  		IPFSAddress:      ipfsAddressStr,
   108  	}, nil
   109  }