ardmk-init runs without prompt by default, cli arg added to avoid clint dependency
This commit is contained in:
parent
78d11c6678
commit
d874c59103
2 changed files with 42 additions and 29 deletions
12
ardmk-init.1
12
ardmk-init.1
|
@ -1,4 +1,4 @@
|
|||
.TH ARDMK-INIT "1" "Oct 2017" "ardmk-init" "Arduino Makefile Generator"
|
||||
.TH ARDMK-INIT "1" "Nov 2017" "ardmk-init" "Arduino Makefile Generator"
|
||||
|
||||
.SH NAME
|
||||
ardmk-init - Generate Arduino Makefile environments
|
||||
|
@ -29,8 +29,8 @@ Monitor port.
|
|||
.B \-n, \-\-name
|
||||
Project name.
|
||||
|
||||
.B \-q, \-\-quiet
|
||||
Run quiet without user prompts.
|
||||
.B \-\-cli
|
||||
Run with user prompts rather than arguments.
|
||||
|
||||
.B \-p, \-\-project
|
||||
Create boilerplate project with src, lib and bin folder structure.
|
||||
|
@ -42,11 +42,11 @@ Create bare minimum Arduino source file.
|
|||
Creates a Makefile and project tree structure from templates.
|
||||
|
||||
.SH EXAMPLE
|
||||
ardmk-init -qb uno # create Arduino uno Makefile quietly
|
||||
ardmk-init -b uno # create Arduino uno Makefile
|
||||
.PP
|
||||
ardmk-init # run with user prompts
|
||||
ardmk-init --cli # run with user prompts
|
||||
.PP
|
||||
ardmk-init --board uno --project --template --name my-project --quiet # create Arduino uno project and template with name "my-project"
|
||||
ardmk-init --board uno --project --template --name my-project # create Arduino uno project and template with name "my-project"
|
||||
|
||||
.SH BUGS
|
||||
Problems may reported on the github project page at:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue