Sagi Dayan
29e31c5b21
All checks were successful
CI / check for spelling errors (pull_request) Successful in 21s
CI / code quality (lint/tests) (pull_request) Successful in 2m6s
CI / make sure build does not fail (pull_request) Successful in 2m22s
CI / notify-fail (pull_request) Has been skipped
CI / check for spelling errors (push) Successful in 21s
CI / code quality (lint/tests) (push) Successful in 2m4s
CI / make sure build does not fail (push) Successful in 2m24s
CI / notify-fail (push) Has been skipped
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
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)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
configuration.RemoveProject(project)
|
|
configuration.Save()
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
projectFlags.projectPath = rmProjectCmd.Flags().StringP("project-path", "p", "", "project path to remove")
|
|
|
|
err := rmProjectCmd.MarkFlagRequired("project-path")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = rmProjectCmd.RegisterFlagCompletionFunc("project-path", validProjectPathComplete)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
projectCmd.AddCommand(lsProjectCmd)
|
|
projectCmd.AddCommand(rmProjectCmd)
|
|
}
|