@@ -7,12 +7,12 @@ for use with Arduino-mk. Addionally, it can be used to create a template
77Arduino source file and a traditional boilerplate project file structure.
88
99Example:
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`
1212 * 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`
1414 * 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`
1616
1717See `armk-init --help` for CLI arguments
1818"""
@@ -22,7 +22,7 @@ import os
2222import argparse
2323
2424## Global Vars
25- VERSION = "1.0 "
25+ VERSION = "1.1 "
2626ARD_TEMPLATE = "\n \
2727 #include <Arduino.h>\n \
2828 #include <Wire.h>\n \
@@ -36,30 +36,32 @@ void loop() {\n\
3636 "
3737
3838## 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.\
4041 For use with Ard-Makefile: https://github.com/sudar/Arduino-Makefile.\
4142 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 )
4344PARSER .add_argument ('-v' , '--verbose' , action = 'store_true' ,
4445 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 ' )
4647PARSER .add_argument ('-b' , '--board' , default = 'uno' , help = 'board tag' )
4748PARSER .add_argument ('-u' , '--micro' , default = 'AUTO' , help = 'microcontroller on board' )
4849PARSER .add_argument ('-f' , '--freq' , default = 'AUTO' , help = 'clock frequency' )
4950PARSER .add_argument ('-p' , '--port' , default = 'AUTO' , help = 'monitor port' )
5051PARSER .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 ' )
5253PARSER .add_argument ('-P' , '--project' , action = 'store_true' ,
5354 help = 'create boilerplate project with src, lib and bin folder structure' )
5455PARSER .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 )
5658ARGS = PARSER .parse_args ()
5759
5860try :
5961 from clint .textui import prompt , validators
6062except 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" )
6365 quit ()
6466
6567
@@ -71,7 +73,7 @@ def generate_makefile():
7173 file_content = "# Generated by ard-make version " + VERSION + "\n \n "
7274
7375 # Basic
74- if not ARGS .quiet :
76+ if ARGS .cli :
7577 print ("Generating Arduino Ard-Makefile project in "
7678 + os .path .abspath (ARGS .directory ))
7779 btag = prompt .query ('Board tag?' , default = 'uno' )
@@ -94,13 +96,13 @@ def generate_makefile():
9496 file_content += check_define ('MONITOR_PORT' , monitor_port )
9597
9698 # Extended
97- if not ARGS .quiet :
99+ if ARGS .cli :
98100 if not prompt .yn ('Extended options?' , default = 'n' ):
99101 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 = [])
102104 userlibs = prompt .query ('Library folder (will create if does not exist) - AUTO is Sketchbook directory?' ,
103- default = 'AUTO' , validators = [])
105+ default = 'AUTO' , validators = [])
104106 obj_dir = prompt .query ('Output directory?' , default = 'AUTO' , validators = [])
105107 else :
106108 src_dir = ''
@@ -171,9 +173,9 @@ def generate_makefile():
171173 file_content += check_define ('TARGET' , ARGS .name )
172174
173175 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" )
177179 else :
178180 ardmk = prompt .query ('Arduino Makefile path?' ,
179181 default = '/usr/share/arduino' ,
@@ -207,7 +209,7 @@ def write_template(filename):
207209 """
208210 print ("Writing " + os .path .abspath (filename ) + ".ino..." )
209211 if os .path .isfile (filename + '.ino' ):
210- if ARGS .quiet :
212+ if not ARGS .cli :
211213 print (filename + '.ino' + ' already exists! Stopping.' )
212214 return
213215 print (filename + '.ino' + ' already exists! Overwrite?' )
@@ -241,15 +243,26 @@ def check_define(define, user):
241243
242244 return string
243245
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+
244255if __name__ == '__main__' :
245256 # Create directory if not exist
246257 check_create_folder (ARGS .directory )
258+ # Check input args
259+ check_args ()
247260 # Change to dir so all commands are run relative
248261 os .chdir (ARGS .directory )
249262 if os .path .isfile ('Makefile' ):
250- if ARGS .quiet :
263+ if not ARGS .cli :
251264 print ('Makefile in ' + os .path .abspath (ARGS .directory )
252- + ' already exists! Stopping.' )
265+ + ' already exists! Please remove before generating. Stopping.' )
253266 quit ()
254267
255268 # Confirm with user if not quiet mode
0 commit comments