2024-11-22 15:29:25 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type projectCmdFlags struct {
|
|
|
|
projectPath *string
|
|
|
|
}
|
|
|
|
|
|
|
|
var projectFlags = projectCmdFlags{}
|
|
|
|
|
|
|
|
var projectCmd = &cobra.Command{
|
|
|
|
Use: "project",
|
|
|
|
Short: "manage project",
|
|
|
|
Long: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
var lsProjectCmd = &cobra.Command{
|
|
|
|
Use: "ls",
|
|
|
|
Short: "list all projects for this user",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
for _, proj := range configuration.Projects {
|
|
|
|
fmt.Printf("%s\t%s\n", proj.Name, proj.Path)
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
var rmProjectCmd = &cobra.Command{
|
|
|
|
Use: "rm",
|
|
|
|
Short: "remove a project definition. the `.envoid` file will not be removed",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
project, err := configuration.GetProject(*projectFlags.projectPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
configuration.RemoveProject(project)
|
|
|
|
configuration.Save()
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
projectFlags.projectPath = rmProjectCmd.Flags().StringP("project-path", "p", "", "project path to remove")
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
err := rmProjectCmd.MarkFlagRequired("project-path")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
err = rmProjectCmd.RegisterFlagCompletionFunc("project-path", validProjectPathComplete)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
projectCmd.AddCommand(lsProjectCmd)
|
|
|
|
projectCmd.AddCommand(rmProjectCmd)
|
|
|
|
}
|