mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
take args from command line
This commit is contained in:
parent
ee3ea218f8
commit
9dac0c76c7
5 changed files with 62 additions and 17 deletions
|
@ -498,11 +498,11 @@ def salt_spm():
|
|||
spm.run()
|
||||
|
||||
|
||||
def salt_extend():
|
||||
def salt_extend(extension, name, salt_dir, merge):
|
||||
'''
|
||||
Quickstart for developing on the saltstack installation
|
||||
|
||||
.. versionadded:: Carbon
|
||||
'''
|
||||
import salt.utils.extend
|
||||
salt.utils.extend.run()
|
||||
salt.utils.extend.run(extension, name, salt_dir, merge)
|
||||
|
|
|
@ -4,6 +4,8 @@ SaltStack Extend
|
|||
'''
|
||||
from __future__ import absolute_import
|
||||
from datetime import date
|
||||
import tempfile
|
||||
from shutil import copytree
|
||||
|
||||
try:
|
||||
import logging
|
||||
|
@ -20,37 +22,48 @@ MODULE_OPTIONS = [
|
|||
]
|
||||
|
||||
|
||||
def run():
|
||||
assert HAS_COOKIECUTTER
|
||||
def run(extension=None, name=None, salt_dir='.', merge=False, temp_dir=None):
|
||||
assert HAS_COOKIECUTTER, "Cookiecutter is not installed, please install using pip"
|
||||
|
||||
print('Choose which kind of extension you are developing for SaltStack')
|
||||
extension_type = 'Extension type'
|
||||
extension_type = prompt.read_user_choice(extension_type, MODULE_OPTIONS)
|
||||
if extension is None:
|
||||
print('Choose which kind of extension you are developing for SaltStack')
|
||||
extension_type = 'Extension type'
|
||||
extension_type = prompt.read_user_choice(extension_type, MODULE_OPTIONS)
|
||||
else:
|
||||
assert extension in list(zip(MODULE_OPTIONS)[0]), "Module extension option not valid"
|
||||
extension_type = extension
|
||||
|
||||
print('Enter the short name for the module (e.g. mymodule)')
|
||||
extension_module_name = prompt.read_user_variable('Module name', '')
|
||||
if name is None:
|
||||
print('Enter the short name for the module (e.g. mymodule)')
|
||||
name = prompt.read_user_variable('Module name', '')
|
||||
|
||||
short_description = prompt.read_user_variable('Short description of the module', '')
|
||||
|
||||
template_dir = 'templates/{0}'.format(extension_type[0])
|
||||
project_name = extension_module_name
|
||||
project_name = name
|
||||
|
||||
param_dict = {
|
||||
"full_name": "",
|
||||
"email": "",
|
||||
"project_name": project_name,
|
||||
"project_slug": 'salt',
|
||||
"repo_name": project_name,
|
||||
"project_short_description": short_description,
|
||||
"release_date": date.today().strftime('%Y-%m-%d'),
|
||||
"year": date.today().strftime('%Y'),
|
||||
"version": "0.1.1"
|
||||
}
|
||||
|
||||
if temp_dir is None:
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
|
||||
cookie(template=template_dir,
|
||||
no_input=True,
|
||||
extra_context=param_dict)
|
||||
|
||||
extra_context=param_dict,
|
||||
output_dir=temp_dir)
|
||||
|
||||
if not merge:
|
||||
print('New module stored in {0}'.format(temp_dir))
|
||||
else:
|
||||
copytree(temp_dir, salt_dir)
|
||||
print('New module stored in {0}'.format(salt_dir))
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
|
|
@ -5,4 +5,28 @@ Quickstart for creating an/or extending the functionality of your SaltStack inst
|
|||
from salt.scripts import salt_extend
|
||||
|
||||
if __name__ == '__main__':
|
||||
salt_extend()
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--extension",
|
||||
"-e",
|
||||
help="Extension type, e.g. 'module', 'state'.")
|
||||
parser.add_argument(
|
||||
"--salt-directory",
|
||||
"-d",
|
||||
help="Directory where your salt installation is kept (defaults to .).")
|
||||
parser.add_argument(
|
||||
"--name",
|
||||
"-n",
|
||||
help="Module name.")
|
||||
parser.add_argument(
|
||||
"--no-merge",
|
||||
help="Don't merge the module into the salt directory, keep in a temp location",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
salt_extend(extension=args.extension,
|
||||
name=args.name,
|
||||
salt_dir=args.salt_directory,
|
||||
merge=not args.no_merge)
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
{
|
||||
"full_name": "",
|
||||
"email": "",
|
||||
"project_name": "project_name",
|
||||
"project_slug": "salt",
|
||||
"repo_name": "project_name",
|
||||
"project_short_description": "short_description",
|
||||
"release_date": "2016-06-06",
|
||||
"year": "2016",
|
||||
"version": "Carbon",
|
||||
"open_source_license": ["Apache Software License 2.0"]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue