♻️ make use of command Args
This commit is contained in:
parent
08f1ccb99b
commit
47a184b89c
@ -32,7 +32,7 @@ import (
|
|||||||
var listCmd = &cobra.Command{
|
var listCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "A brief description of your command",
|
Short: "A brief description of your command",
|
||||||
Long: "",
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := tmux.ListProjects()
|
err := tmux.ListProjects()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,11 +32,8 @@ import (
|
|||||||
var newCmd = &cobra.Command{
|
var newCmd = &cobra.Command{
|
||||||
Use: "new [NAME]",
|
Use: "new [NAME]",
|
||||||
Short: "Create a new project",
|
Short: "Create a new project",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) < 1 {
|
|
||||||
fmt.Println("Provide a project name")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err := tmux.NewProject(args[0])
|
err := tmux.NewProject(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to create project:", err)
|
fmt.Println("Unable to create project:", err)
|
||||||
|
@ -22,8 +22,6 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/walkah/workon/tmux"
|
"github.com/walkah/workon/tmux"
|
||||||
)
|
)
|
||||||
@ -32,12 +30,8 @@ import (
|
|||||||
var startCmd = &cobra.Command{
|
var startCmd = &cobra.Command{
|
||||||
Use: "start [PROJECT]",
|
Use: "start [PROJECT]",
|
||||||
Short: "Start working on a project",
|
Short: "Start working on a project",
|
||||||
Long: "",
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) < 1 {
|
|
||||||
fmt.Println("No project given")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tmux.StartProject(args[0])
|
tmux.StartProject(args[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user