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