@@ -7,12 +7,12 @@ for use with Arduino-mk. Addionally, it can be used to create a template
7
7
Arduino source file and a traditional boilerplate project file structure.
8
8
9
9
Example:
10
- * Run prompted within current working directory: `ardmk-init`
11
- * Create Arduino Uno Makefile (useful within a library example): `ardmk-init -qb uno`
10
+ * Run prompted within current working directory (requires Clint) : `ardmk-init --cli `
11
+ * Create Arduino Uno Makefile (useful within a library example): `ardmk-init -b uno`
12
12
* Create boilerplate Arduino Uno project in current working directory of same
13
- name: `ardmk-init -b uno --quiet -- project`
13
+ name: `ardmk-init -b uno --project`
14
14
* Create Arduino-mk nano Makefile in current working directory with template .ino:
15
- `ardmk-init -b nano -u atmega328 -qtn my-project`
15
+ `ardmk-init -b nano -u atmega328 -tn my-project`
16
16
17
17
See `armk-init --help` for CLI arguments
18
18
"""
@@ -22,7 +22,7 @@ import os
22
22
import argparse
23
23
24
24
## Global Vars
25
- VERSION = "1.0 "
25
+ VERSION = "1.1 "
26
26
ARD_TEMPLATE = "\n \
27
27
#include <Arduino.h>\n \
28
28
#include <Wire.h>\n \
@@ -36,30 +36,32 @@ void loop() {\n\
36
36
"
37
37
38
38
## Command Parser
39
- PARSER = argparse .ArgumentParser (description = 'Arduino Makefile and boilerplate project generator.\
39
+ PARSER = argparse .ArgumentParser (prog = 'ardmk-init' ,
40
+ description = 'Arduino Makefile and boilerplate project generator.\
40
41
For use with Ard-Makefile: https://github.com/sudar/Arduino-Makefile.\
41
42
Script created by John Whittington https://github.com/tuna-f1sh 2017\
42
- \n \n Version: ' + VERSION , usage = 'ardmk-init # prompted CLI, see --help for more.' )
43
+ \n \n Version: ' + VERSION )
43
44
PARSER .add_argument ('-v' , '--verbose' , action = 'store_true' ,
44
45
help = "print file contents during creation" )
45
- PARSER .add_argument ('-d' , '--directory' , default = os .getcwd (), help = 'directory to run generator' )
46
+ PARSER .add_argument ('-d' , '--directory' , default = os .getcwd (), help = 'directory to run generator, default cwd ' )
46
47
PARSER .add_argument ('-b' , '--board' , default = 'uno' , help = 'board tag' )
47
48
PARSER .add_argument ('-u' , '--micro' , default = 'AUTO' , help = 'microcontroller on board' )
48
49
PARSER .add_argument ('-f' , '--freq' , default = 'AUTO' , help = 'clock frequency' )
49
50
PARSER .add_argument ('-p' , '--port' , default = 'AUTO' , help = 'monitor port' )
50
51
PARSER .add_argument ('-n' , '--name' , default = os .path .basename (os .getcwd ()), help = 'project name' )
51
- PARSER .add_argument ('-q' , '--quiet ' , action = 'store_true' , help = 'run quiet without user prompts' )
52
+ PARSER .add_argument ('--cli ' , action = 'store_true' , help = 'run with user prompts (requires "Clint" module), rather than args ' )
52
53
PARSER .add_argument ('-P' , '--project' , action = 'store_true' ,
53
54
help = 'create boilerplate project with src, lib and bin folder structure' )
54
55
PARSER .add_argument ('-t' , '--template' , action = 'store_true' ,
55
- help = 'create bare minimum Arduino source file' )
56
+ help = 'create bare minimum Arduino source file' )
57
+ PARSER .add_argument ('-V' , '--version' , action = 'version' , version = '%(prog)s ' + VERSION )
56
58
ARGS = PARSER .parse_args ()
57
59
58
60
try :
59
61
from clint .textui import prompt , validators
60
62
except ImportError :
61
- if not ARGS .quiet :
62
- print ("Python module 'clint' is required for running prompted. Install the module or run with arguments only using --quiet " )
63
+ if ARGS .cli :
64
+ print ("Python module 'clint' is required for running prompted. Install the module or run with arguments only" )
63
65
quit ()
64
66
65
67
@@ -71,7 +73,7 @@ def generate_makefile():
71
73
file_content = "# Generated by ard-make version " + VERSION + "\n \n "
72
74
73
75
# Basic
74
- if not ARGS .quiet :
76
+ if ARGS .cli :
75
77
print ("Generating Arduino Ard-Makefile project in "
76
78
+ os .path .abspath (ARGS .directory ))
77
79
btag = prompt .query ('Board tag?' , default = 'uno' )
@@ -94,13 +96,13 @@ def generate_makefile():
94
96
file_content += check_define ('MONITOR_PORT' , monitor_port )
95
97
96
98
# Extended
97
- if not ARGS .quiet :
99
+ if ARGS .cli :
98
100
if not prompt .yn ('Extended options?' , default = 'n' ):
99
101
if not prompt .yn ('Define local folders?' , default = 'n' ):
100
- src_dir = prompt .query ('Sources folder (Makefile will be created here)?' ,\
101
- default = '' , validators = [])
102
+ src_dir = prompt .query ('Sources folder (Makefile will be created here)?' ,
103
+ default = '' , validators = [])
102
104
userlibs = prompt .query ('Library folder (will create if does not exist) - AUTO is Sketchbook directory?' ,
103
- default = 'AUTO' , validators = [])
105
+ default = 'AUTO' , validators = [])
104
106
obj_dir = prompt .query ('Output directory?' , default = 'AUTO' , validators = [])
105
107
else :
106
108
src_dir = ''
@@ -171,9 +173,9 @@ def generate_makefile():
171
173
file_content += check_define ('TARGET' , ARGS .name )
172
174
173
175
if not "ARDMK_DIR" in os .environ :
174
- if ARGS .quiet :
175
- puts ( colored . magenta ( ' Warning: ARDMK_DIR environment variable not defined. \
176
- Must be defined for Makefile to work' ) )
176
+ if not ARGS .cli :
177
+ print ( " Warning: ARDMK_DIR environment variable not defined. \
178
+ Must be defined for Makefile to work" )
177
179
else :
178
180
ardmk = prompt .query ('Arduino Makefile path?' ,
179
181
default = '/usr/share/arduino' ,
@@ -207,7 +209,7 @@ def write_template(filename):
207
209
"""
208
210
print ("Writing " + os .path .abspath (filename ) + ".ino..." )
209
211
if os .path .isfile (filename + '.ino' ):
210
- if ARGS .quiet :
212
+ if not ARGS .cli :
211
213
print (filename + '.ino' + ' already exists! Stopping.' )
212
214
return
213
215
print (filename + '.ino' + ' already exists! Overwrite?' )
@@ -241,15 +243,26 @@ def check_define(define, user):
241
243
242
244
return string
243
245
246
+ def check_args ():
247
+ """
248
+ Check input args will work with Makefile
249
+ """
250
+ # Micro should be defined for non uno boards
251
+ if ARGS .board != 'uno' and ARGS .micro == 'AUTO' :
252
+ print ('\n !!! Warning: --micro should be defined and not left AUTO for non-Uno boards\n ' )
253
+
254
+
244
255
if __name__ == '__main__' :
245
256
# Create directory if not exist
246
257
check_create_folder (ARGS .directory )
258
+ # Check input args
259
+ check_args ()
247
260
# Change to dir so all commands are run relative
248
261
os .chdir (ARGS .directory )
249
262
if os .path .isfile ('Makefile' ):
250
- if ARGS .quiet :
263
+ if not ARGS .cli :
251
264
print ('Makefile in ' + os .path .abspath (ARGS .directory )
252
- + ' already exists! Stopping.' )
265
+ + ' already exists! Please remove before generating. Stopping.' )
253
266
quit ()
254
267
255
268
# Confirm with user if not quiet mode
0 commit comments