2024-09-27 00:38:01 +00:00
|
|
|
// Start services
|
|
|
|
//
|
|
|
|
// Commands related to starting services.
|
|
|
|
|
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2024-09-29 01:47:48 +00:00
|
|
|
"fmt"
|
2024-09-27 00:38:01 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
service "spud/service"
|
|
|
|
service_definition "spud/service_definition"
|
|
|
|
)
|
|
|
|
|
2024-09-29 01:47:48 +00:00
|
|
|
func getStartCommand() *cobra.Command {
|
|
|
|
start := &cobra.Command{
|
|
|
|
Use: "start",
|
|
|
|
Short: "Creates or updates a service based on the provided definition.",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
pathProvided, err := cmd.PersistentFlags().GetString("definition")
|
2024-09-27 00:38:01 +00:00
|
|
|
|
2024-09-29 01:47:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("%+v", err)
|
|
|
|
}
|
2024-09-27 00:38:01 +00:00
|
|
|
|
2024-09-29 01:47:48 +00:00
|
|
|
def, err := service_definition.GetServiceDefinitionFromFile(pathProvided)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to read service definition from file: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
service.CreateService(def)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
start.PersistentFlags().StringP("definition", "d", "./service.yml", "Path to the service definition to use.")
|
|
|
|
|
|
|
|
return start
|
2024-09-27 00:38:01 +00:00
|
|
|
}
|