File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "errors"
5
+ "flag"
6
+ "fmt"
7
+ "io/fs"
8
+ "log"
9
+ "os"
10
+ "path"
11
+ )
12
+
13
+ func main () {
14
+ cwd , err := os .Getwd ()
15
+ if err != nil {
16
+ log .Fatal (err )
17
+ }
18
+ initCmd := flag .NewFlagSet ("init" , flag .ExitOnError )
19
+ targetDir := initCmd .String ("d" , cwd , "Target directory" )
20
+ prefix := initCmd .String ("p" , "sketch" , "Project prefix" )
21
+ if len (os .Args ) < 2 {
22
+ fmt .Println ("expected 'init' or 'run' subcommands" )
23
+ os .Exit (1 )
24
+ }
25
+ switch os .Args [1 ] {
26
+ case "init" :
27
+ initCmd .Parse (os .Args [2 :])
28
+ dirPath := path .Join (* targetDir , * prefix )
29
+ if _ , err := os .Stat (dirPath ); errors .Is (err , fs .ErrExist ) {
30
+ log .Fatal ("can't make directory: " , err )
31
+ }
32
+ err := os .Mkdir (dirPath , 0644 )
33
+ if err != nil {
34
+ log .Fatal ("error while creating directory: " , err )
35
+ }
36
+ }
37
+ }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments