-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module add #166
base: master
Are you sure you want to change the base?
Module add #166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,59 @@ def do_override(params): | |
print('{}: {}'.format(module, params.runtime.get_override(module))) | ||
|
||
|
||
@peru_command('module', '''\ | ||
Usage: | ||
peru module add [<module>] [<url>] [<type>] [--rev=<rev>] [--reup=<reup>] | ||
[--filename=<filename>] [--sha=<sha>] [--unpack=<unpack>] [--yaml=<yaml>] | ||
peru module --help | ||
|
||
Add a module to your Peru yaml file. Reguires a module name, url, and module type. | ||
|
||
Options: | ||
add add new module | ||
--rev=<rev> set module rev value | ||
--reup=<reup> set module reup value | ||
--filename=<filename> set module filemame value | ||
--sha=<sha> set module sha1 value | ||
--unpack=<unpack> set module unpack value | ||
--yaml=<yaml> file to use instead of peru.yaml | ||
--help | ||
''') | ||
def do_add(params): | ||
if params.args['add']: | ||
if not params.args['<module>']: | ||
params.runtime.display.print('Please specify a module to add. See usage with peru module --help') | ||
elif not params.args['<url>']: | ||
params.runtime.display.print('Please specify a module url. See usage with peru module --help') | ||
elif not params.args['<type>']: | ||
params.runtime.display.print('Please specify a module type. See usage with peru module --help') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing all the work to check required fields in code, just make them required in the docopt string above, by removing the surrounding |
||
else: | ||
peru_file = params.args['--yaml'] if params.args['--yaml'] else 'peru.yaml' | ||
|
||
if(peru_file[-5:] != '.yaml'): | ||
params.runtime.display.print('Peru file should end in .yaml. See usage with peru add --help') | ||
|
||
else: | ||
with open(peru_file, "a") as yaml: | ||
yaml.write('\n' + params.args['<type>'] + ' module ' + params.args['<module>'] + ':') | ||
if(params.args['<url>']): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is mandatory, so we probably don't need the |
||
yaml.write('\n url: ' + params.args['<url>']) | ||
if(params.args['--rev']): | ||
yaml.write('\n rev: ' + params.args['--rev']) | ||
if(params.args['--reup']): | ||
yaml.write('\n reup: ' + params.args['--reup']) | ||
if(params.args['--filename']): | ||
yaml.write('\n filename: ' + params.args['--filename']) | ||
if(params.args['--sha']): | ||
yaml.write('\n sha: ' + params.args['--sha']) | ||
if(params.args['--unpack']): | ||
yaml.write('\n unpack: ' + params.args['--unpack']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of similar to what came up in #165, because we support user-defined module types, we need to be prepared for modules with new field names that we don't know about yet. Hardcoding the field names as flags like this makes it hard to handle that case. |
||
yaml.write('\n') | ||
yaml.close() | ||
|
||
params.runtime.display.print('{} module added to {}'.format(params.args['<module>'], peru_file)) | ||
|
||
|
||
def get_version(): | ||
version_file = os.path.join(compat.MODULE_ROOT, 'VERSION') | ||
with open(version_file) as f: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
--file
and--file-basename
flags that we already have at the top level might make--yaml
unnecessary. (That said, currently specifying--file
requires that you also specify--sync-dir
. That might be overkill here. Not sure yet.)