parent
fc05aed4c0
commit
5825a1b2b4
@ -34,10 +34,14 @@ var listCmd = &cobra.Command{
|
||||
Short: "A brief description of your command",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := tmux.ListProjects()
|
||||
projects, err := tmux.ListProjects()
|
||||
if err != nil {
|
||||
fmt.Println("Unable to list projects:", err)
|
||||
}
|
||||
|
||||
for _, project := range projects {
|
||||
fmt.Println(project)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,14 @@ var psCmd = &cobra.Command{
|
||||
Use: "ps",
|
||||
Short: "List currently running projects.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
t := tmux.Tmux{}
|
||||
for _, project := range t.ListSessions() {
|
||||
fmt.Println(project)
|
||||
projects, err := tmux.ListActiveProjects()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
for _, project := range projects {
|
||||
fmt.Println(project)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ var rootCmd = &cobra.Command{
|
||||
Long: "",
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 1 {
|
||||
return errors.New("No project or command given")
|
||||
return errors.New("no project or command given")
|
||||
}
|
||||
startCmd.Run(cmd, args)
|
||||
return nil
|
||||
@ -54,7 +54,7 @@ var rootCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func completeProjects(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
projects, err := tmux.ProjectList()
|
||||
projects, err := tmux.ListProjects()
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ var stopCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var projects []string
|
||||
if len(args) == 0 {
|
||||
t := tmux.Tmux{}
|
||||
projects = t.ListSessions()
|
||||
projects, _ = tmux.ListActiveProjects()
|
||||
} else {
|
||||
projects = args
|
||||
}
|
||||
|
@ -66,20 +66,24 @@ func StopProject(name string) {
|
||||
p.RunCommands(p.OnProjectStop)
|
||||
}
|
||||
|
||||
func ListProjects() error {
|
||||
projects, err := ProjectList()
|
||||
func ListActiveProjects() ([]string, error) {
|
||||
activeProjects := []string{}
|
||||
|
||||
projects, err := ListProjects()
|
||||
if err != nil {
|
||||
return err
|
||||
return activeProjects, err
|
||||
}
|
||||
|
||||
for _, project := range projects {
|
||||
fmt.Printf("%s\n", project)
|
||||
if sessionExists(project) {
|
||||
activeProjects = append(activeProjects, project)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return activeProjects, nil
|
||||
}
|
||||
|
||||
// ProjectList gets a list of
|
||||
func ProjectList() ([]string, error) {
|
||||
func ListProjects() ([]string, error) {
|
||||
configDir := getConfigDir()
|
||||
files, err := ioutil.ReadDir(configDir)
|
||||
if err != nil {
|
||||
@ -112,7 +116,7 @@ func LoadProject(name string) (*Project, error) {
|
||||
|
||||
err = yaml.Unmarshal(data, project)
|
||||
if len(project.Windows) < 1 {
|
||||
return project, errors.New("No windows defined")
|
||||
return project, errors.New("no windows defined")
|
||||
}
|
||||
|
||||
rootPath := project.GetRoot()
|
||||
@ -157,7 +161,7 @@ func EditProject(name string) error {
|
||||
|
||||
_, err := os.Stat(fileName)
|
||||
if err != nil {
|
||||
return errors.New("Config file does not exist")
|
||||
return errors.New("config file does not exist")
|
||||
}
|
||||
|
||||
editorName := os.Getenv("EDITOR")
|
||||
@ -178,7 +182,7 @@ func (p *Project) Save() error {
|
||||
|
||||
_, err := os.Stat(fileName)
|
||||
if err == nil {
|
||||
return errors.New("Config file already exists")
|
||||
return errors.New("config file already exists")
|
||||
}
|
||||
|
||||
data, err := yaml.Marshal(p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user