(persistentPreRunE ...cobraFunc)
| 49 | } |
| 50 | |
| 51 | func servicesCmd(persistentPreRunE ...cobraFunc) *cobra.Command { |
| 52 | flags := servicesCmdFlags{} |
| 53 | serviceUpFlags := serviceUpFlags{} |
| 54 | serviceStopFlags := serviceStopFlags{} |
| 55 | servicesCommand := &cobra.Command{ |
| 56 | Use: "services", |
| 57 | Short: "Interact with devbox services.", |
| 58 | Long: "Interact with devbox services. Services start in a new shell. " + |
| 59 | "Plugin services use environment variables specified by plugin unless " + |
| 60 | "overridden by the user. To override plugin environment variables, use " + |
| 61 | "the --env or --env-file flag. You may also override in devbox.json by " + |
| 62 | "using the `env` field or exporting an environment variable in the " + |
| 63 | "init hook.", |
| 64 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 65 | preruns := append([]cobraFunc{ensureNixInstalled}, persistentPreRunE...) |
| 66 | for _, fn := range preruns { |
| 67 | if err := fn(cmd, args); err != nil { |
| 68 | return err |
| 69 | } |
| 70 | } |
| 71 | return nil |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | attachCommand := &cobra.Command{ |
| 76 | Use: "attach", |
| 77 | Short: "Attach to a running process-compose for the current project", |
| 78 | Args: cobra.ExactArgs(0), |
| 79 | RunE: func(cmd *cobra.Command, args []string) error { |
| 80 | return attachServices(cmd, flags) |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | lsCommand := &cobra.Command{ |
| 85 | Use: "ls", |
| 86 | Short: "List available services", |
| 87 | Args: cobra.ExactArgs(0), |
| 88 | RunE: func(cmd *cobra.Command, args []string) error { |
| 89 | return listServices(cmd, flags) |
| 90 | }, |
| 91 | } |
| 92 | |
| 93 | startCommand := &cobra.Command{ |
| 94 | Use: "start [service]...", |
| 95 | Short: "Start service. If no service is specified, starts all services", |
| 96 | RunE: func(cmd *cobra.Command, args []string) error { |
| 97 | return startServices(cmd, args, flags) |
| 98 | }, |
| 99 | } |
| 100 | |
| 101 | stopCommand := &cobra.Command{ |
| 102 | Use: "stop [service]...", |
| 103 | Aliases: []string{"down"}, |
| 104 | Short: `Stop one or more services in the current project. If no service is specified, stops all services in the current project.`, |
| 105 | Long: `Stop one or more services in the current project. If no service is specified, stops all services in the current project. \nIf the --all-projects flag is specified, stops all running services across all your projects. This flag cannot be used with [service] arguments.`, |
| 106 | RunE: func(cmd *cobra.Command, args []string) error { |
| 107 | return stopServices(cmd, args, flags, serviceStopFlags) |
| 108 | }, |
no test coverage detected