Skip to content

Commit d874c59

Browse files
committed
ardmk-init runs without prompt by default, cli arg added to avoid clint dependency
1 parent 78d11c6 commit d874c59

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

ardmk-init.1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH ARDMK-INIT "1" "Oct 2017" "ardmk-init" "Arduino Makefile Generator"
1+
.TH ARDMK-INIT "1" "Nov 2017" "ardmk-init" "Arduino Makefile Generator"
22

33
.SH NAME
44
ardmk-init - Generate Arduino Makefile environments
@@ -29,8 +29,8 @@ Monitor port.
2929
.B \-n, \-\-name
3030
Project name.
3131

32-
.B \-q, \-\-quiet
33-
Run quiet without user prompts.
32+
.B \-\-cli
33+
Run with user prompts rather than arguments.
3434

3535
.B \-p, \-\-project
3636
Create boilerplate project with src, lib and bin folder structure.
@@ -42,11 +42,11 @@ Create bare minimum Arduino source file.
4242
Creates a Makefile and project tree structure from templates.
4343

4444
.SH EXAMPLE
45-
ardmk-init -qb uno # create Arduino uno Makefile quietly
45+
ardmk-init -b uno # create Arduino uno Makefile
4646
.PP
47-
ardmk-init # run with user prompts
47+
ardmk-init --cli # run with user prompts
4848
.PP
49-
ardmk-init --board uno --project --template --name my-project --quiet # create Arduino uno project and template with name "my-project"
49+
ardmk-init --board uno --project --template --name my-project # create Arduino uno project and template with name "my-project"
5050

5151
.SH BUGS
5252
Problems may reported on the github project page at:

bin/ardmk-init

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ for use with Arduino-mk. Addionally, it can be used to create a template
77
Arduino source file and a traditional boilerplate project file structure.
88
99
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`
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
1717
See `armk-init --help` for CLI arguments
1818
"""
@@ -22,7 +22,7 @@ import os
2222
import argparse
2323

2424
## Global Vars
25-
VERSION = "1.0"
25+
VERSION = "1.1"
2626
ARD_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\nVersion: ' + VERSION, usage='ardmk-init # prompted CLI, see --help for more.')
43+
\n\nVersion: ' + VERSION)
4344
PARSER.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')
4647
PARSER.add_argument('-b', '--board', default='uno', help='board tag')
4748
PARSER.add_argument('-u', '--micro', default='AUTO', help='microcontroller on board')
4849
PARSER.add_argument('-f', '--freq', default='AUTO', help='clock frequency')
4950
PARSER.add_argument('-p', '--port', default='AUTO', help='monitor port')
5051
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')
5253
PARSER.add_argument('-P', '--project', action='store_true',
5354
help='create boilerplate project with src, lib and bin folder structure')
5455
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)
5658
ARGS = PARSER.parse_args()
5759

5860
try:
5961
from clint.textui import prompt, validators
6062
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")
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+
244255
if __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

Comments
 (0)