aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ardmk-init59
1 files changed, 36 insertions, 23 deletions
diff --git a/bin/ardmk-init b/bin/ardmk-init
index 461e9ab..1a01cd3 100755
--- a/bin/ardmk-init
+++ b/bin/ardmk-init
@@ -7,12 +7,12 @@ for use with Arduino-mk. Addionally, it can be used to create a template
Arduino source file and a traditional boilerplate project file structure.
Example:
- * Run prompted within current working directory: `ardmk-init`
- * Create Arduino Uno Makefile (useful within a library example): `ardmk-init -qb uno`
+ * Run prompted within current working directory (requires Clint): `ardmk-init --cli`
+ * Create Arduino Uno Makefile (useful within a library example): `ardmk-init -b uno`
* Create boilerplate Arduino Uno project in current working directory of same
- name: `ardmk-init -b uno --quiet --project`
+ name: `ardmk-init -b uno --project`
* Create Arduino-mk nano Makefile in current working directory with template .ino:
- `ardmk-init -b nano -u atmega328 -qtn my-project`
+ `ardmk-init -b nano -u atmega328 -tn my-project`
See `armk-init --help` for CLI arguments
"""
@@ -22,7 +22,7 @@ import os
import argparse
## Global Vars
-VERSION = "1.0"
+VERSION = "1.1"
ARD_TEMPLATE = "\n\
#include <Arduino.h>\n\
#include <Wire.h>\n\
@@ -36,30 +36,32 @@ void loop() {\n\
"
## Command Parser
-PARSER = argparse.ArgumentParser(description='Arduino Makefile and boilerplate project generator.\
+PARSER = argparse.ArgumentParser(prog='ardmk-init',
+ description='Arduino Makefile and boilerplate project generator.\
For use with Ard-Makefile: https://github.com/sudar/Arduino-Makefile.\
Script created by John Whittington https://github.com/tuna-f1sh 2017\
- \n\nVersion: ' + VERSION, usage='ardmk-init # prompted CLI, see --help for more.')
+ \n\nVersion: ' + VERSION)
PARSER.add_argument('-v', '--verbose', action='store_true',
help="print file contents during creation")
-PARSER.add_argument('-d', '--directory', default=os.getcwd(), help='directory to run generator')
+PARSER.add_argument('-d', '--directory', default=os.getcwd(), help='directory to run generator, default cwd')
PARSER.add_argument('-b', '--board', default='uno', help='board tag')
PARSER.add_argument('-u', '--micro', default='AUTO', help='microcontroller on board')
PARSER.add_argument('-f', '--freq', default='AUTO', help='clock frequency')
PARSER.add_argument('-p', '--port', default='AUTO', help='monitor port')
PARSER.add_argument('-n', '--name', default=os.path.basename(os.getcwd()), help='project name')
-PARSER.add_argument('-q', '--quiet', action='store_true', help='run quiet without user prompts')
+PARSER.add_argument('--cli', action='store_true', help='run with user prompts (requires "Clint" module), rather than args')
PARSER.add_argument('-P', '--project', action='store_true',
help='create boilerplate project with src, lib and bin folder structure')
PARSER.add_argument('-t', '--template', action='store_true',
- help='create bare minimum Arduino source file')
+ help='create bare minimum Arduino source file')
+PARSER.add_argument('-V', '--version', action='version', version='%(prog)s '+ VERSION)
ARGS = PARSER.parse_args()
try:
from clint.textui import prompt, validators
except ImportError:
- if not ARGS.quiet:
- print("Python module 'clint' is required for running prompted. Install the module or run with arguments only using --quiet")
+ if ARGS.cli:
+ print("Python module 'clint' is required for running prompted. Install the module or run with arguments only")
quit()
@@ -71,7 +73,7 @@ def generate_makefile():
file_content = "# Generated by ard-make version " + VERSION + "\n\n"
# Basic
- if not ARGS.quiet:
+ if ARGS.cli:
print("Generating Arduino Ard-Makefile project in "
+ os.path.abspath(ARGS.directory))
btag = prompt.query('Board tag?', default='uno')
@@ -94,13 +96,13 @@ def generate_makefile():
file_content += check_define('MONITOR_PORT', monitor_port)
# Extended
- if not ARGS.quiet:
+ if ARGS.cli:
if not prompt.yn('Extended options?', default='n'):
if not prompt.yn('Define local folders?', default='n'):
- src_dir = prompt.query('Sources folder (Makefile will be created here)?',\
- default='', validators=[])
+ src_dir = prompt.query('Sources folder (Makefile will be created here)?',
+ default='', validators=[])
userlibs = prompt.query('Library folder (will create if does not exist) - AUTO is Sketchbook directory?',
- default='AUTO', validators=[])
+ default='AUTO', validators=[])
obj_dir = prompt.query('Output directory?', default='AUTO', validators=[])
else:
src_dir = ''
@@ -171,9 +173,9 @@ def generate_makefile():
file_content += check_define('TARGET', ARGS.name)
if not "ARDMK_DIR" in os.environ:
- if ARGS.quiet:
- puts(colored.magenta('Warning: ARDMK_DIR environment variable not defined. \
- Must be defined for Makefile to work'))
+ if not ARGS.cli:
+ print("Warning: ARDMK_DIR environment variable not defined. \
+ Must be defined for Makefile to work")
else:
ardmk = prompt.query('Arduino Makefile path?',
default='/usr/share/arduino',
@@ -207,7 +209,7 @@ def write_template(filename):
"""
print("Writing " + os.path.abspath(filename) + ".ino...")
if os.path.isfile(filename + '.ino'):
- if ARGS.quiet:
+ if not ARGS.cli:
print(filename + '.ino' + ' already exists! Stopping.')
return
print(filename + '.ino' + ' already exists! Overwrite?')
@@ -241,15 +243,26 @@ def check_define(define, user):
return string
+def check_args():
+ """
+ Check input args will work with Makefile
+ """
+ # Micro should be defined for non uno boards
+ if ARGS.board != 'uno' and ARGS.micro == 'AUTO':
+ print('\n!!! Warning: --micro should be defined and not left AUTO for non-Uno boards\n')
+
+
if __name__ == '__main__':
# Create directory if not exist
check_create_folder(ARGS.directory)
+ # Check input args
+ check_args()
# Change to dir so all commands are run relative
os.chdir(ARGS.directory)
if os.path.isfile('Makefile'):
- if ARGS.quiet:
+ if not ARGS.cli:
print('Makefile in ' + os.path.abspath(ARGS.directory)
- + ' already exists! Stopping.')
+ + ' already exists! Please remove before generating. Stopping.')
quit()
# Confirm with user if not quiet mode