@@ -65,41 +65,41 @@ func main() {
6565 args := flag .Args ()
6666
6767 if len (args ) == 0 {
68- fmt .Println ("Error, must provide project name" )
69- return
68+ fmt .Println ("Error: must provide project name" )
69+ os . Exit ( 1 )
7070 }
7171
7272 // the first positional argument is the directory to initialise
7373 projectPath := args [0 ]
7474
75- initDir (projectPath )
75+ err := initDir (projectPath )
76+ if err != nil {
77+ fmt .Printf ("Error: could not init directory: %s" , err )
78+ os .Exit (1 )
79+ }
7680}
7781
78- func initDir (dirPath string ) {
82+ func initDir (dirPath string ) error {
7983 if dirPath == "" {
80- fmt .Println ("Error: must provide project name" )
81- return
84+ return fmt .Errorf ("must provide project name" )
8285 }
8386
8487 fmt .Printf ("%s%s" , kHeader , kDivider )
8588 err := os .Mkdir (dirPath , mkdirPerms )
8689 if err != nil {
8790 if e , ok := err .(* os.PathError ); ok && e .Err != syscall .EEXIST {
88- fmt .Println (err )
89- return
91+ return err
9092 }
9193 }
9294
9395 err = os .Chdir (dirPath )
9496 if err != nil {
95- fmt .Println (err )
96- return
97+ return err
9798 }
9899
99100 templateContents , err := templateFs .ReadDir ("template" )
100101 if err != nil {
101- fmt .Println (err )
102- return
102+ return err
103103 }
104104
105105 fmt .Printf ("Copying template directory...\n " )
@@ -108,55 +108,33 @@ func initDir(dirPath string) {
108108
109109 err = runCmd ("git" , "init" )
110110 if err != nil {
111- fmt .Println (err )
112- return
111+ return err
113112 }
114113
115114 err = runCmd ("python3" , "-m" , "venv" , ".venv" )
116115 if err != nil {
117- fmt .Println (err )
118- return
116+ return err
119117 }
120118
121119 pipExe := ".venv/bin/pip"
122120 for _ , requirement := range pythonRequirements {
123121 err = runCmd (pipExe , "install" , requirement )
124122 if err != nil {
125- fmt .Println (err )
126- return
123+ return err
127124 }
128125 }
129126
130- err = runCmd (".venv/bin/west" , "init" , "-l" , "zephyr " )
127+ err = runCmd (".venv/bin/west" , "init" , "-l" , "app " )
131128 if err != nil {
132- fmt .Println (err )
133- return
129+ return err
134130 }
135131
136132 fmt .Printf ("%s" , kDivider )
137133 fmt .Printf ("Project setup complete!\n \n " )
138- fmt .Printf ("Add required third party projects through zephyr /west.yml\n " )
134+ fmt .Printf ("Add required third party projects through app /west.yml\n " )
139135 fmt .Printf ("Run `source .venv/bin/activate` to set the project's virtual environment\n " )
140136 fmt .Printf ("Run `west update` to update the project\n " )
141- }
142-
143- // Keywords within @@ symbols are replaced with dynamic components
144- func replaceKeyWords (b []byte ) (ret []byte , err error ) {
145- array := bytes .Split (b , []byte ("@" ))
146-
147- for index , val := range array {
148- if index % 2 != 1 {
149- continue
150- }
151- switch string (val ) {
152- case "PROJECT_NAME" :
153- array [index ] = []byte (path .Base (projectPath ))
154- default :
155- continue
156- }
157- }
158- ret = bytes .Join (array , nil )
159- return
137+ return nil
160138}
161139
162140func copyTemplateContents (path string , entries []fs.DirEntry ) {
@@ -192,6 +170,25 @@ func copyTemplateContents(path string, entries []fs.DirEntry) {
192170 }
193171}
194172
173+ // Keywords within @@ symbols are replaced with dynamic components
174+ func replaceKeyWords (b []byte ) (ret []byte , err error ) {
175+ array := bytes .Split (b , []byte ("@" ))
176+
177+ for index , val := range array {
178+ if index % 2 != 1 {
179+ continue
180+ }
181+ switch string (val ) {
182+ case "PROJECT_NAME" :
183+ array [index ] = []byte (path .Base (projectPath ))
184+ default :
185+ continue
186+ }
187+ }
188+ ret = bytes .Join (array , nil )
189+ return
190+ }
191+
195192// Wrapper around exec.Command to start, attach and print output of the command
196193func runCmd (command string , arg ... string ) error {
197194 cmd := exec .Command (command , arg ... )
0 commit comments