GeezerVison is showing github.com — no longer need a flag on create · commitdev/zero@afc46a9
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: cmd/create.go +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,22 +8,24 @@ import ( |
8 | 8 | "github.com/spf13/cobra" |
9 | 9 | ) |
10 | 10 |
|
11 | | -var projectName string |
12 | | - |
13 | 11 | func init() { |
14 | 12 |
|
15 | | - createCmd.PersistentFlags().StringVarP(&projectName, "project-name", "p", "", "project name") |
16 | | - |
17 | 13 | rootCmd.AddCommand(createCmd) |
18 | 14 | } |
19 | 15 |
|
20 | 16 | var createCmd = &cobra.Command{ |
21 | 17 | Use: "create", |
22 | | - Short: "Create new project.", |
| 18 | + Short: "Create new project with provided name.", |
23 | 19 | Run: func(cmd *cobra.Command, args []string) { |
| 20 | + projectName := args[0] |
| 21 | + if projectName == "" { |
| 22 | + log.Panicf("Project name cannot be empty!") |
| 23 | + } |
24 | 24 |
|
25 | 25 | rootDir := fmt.Sprintf("./%v", projectName) |
26 | 26 |
|
| 27 | + log.Printf("Creating project %s.", projectName) |
| 28 | + |
27 | 29 | err := os.Mkdir(rootDir, os.ModePerm) |
28 | 30 | if os.IsExist(err) { |
29 | 31 | log.Fatalf("Directory %v already exists! Error: %v", projectName, err) |
|