feat: Added create subcommand for recipe and chore
refactor: Renamed add template to create template for product and recipe
This commit is contained in:
parent
dd6223f980
commit
ca2d1aa9cf
68
grocy/cli.py
68
grocy/cli.py
@ -192,12 +192,11 @@ def browse(product_id):
|
||||
|
||||
@product.command()
|
||||
@click.option('-t', 'template')
|
||||
def add(template):
|
||||
logger = logging.getLogger('cli.product.add')
|
||||
def create(template):
|
||||
logger = logging.getLogger('cli.product.create')
|
||||
try:
|
||||
cfg = Configuration()
|
||||
cfg.load()
|
||||
logger = logging.getLogger('cli.product.add')
|
||||
meta = Meta()
|
||||
# Get product_groups
|
||||
entity = Entity(name='product_groups')
|
||||
@ -215,18 +214,18 @@ def add(template):
|
||||
if template:
|
||||
loaded_template = cfg.templates(template)
|
||||
else:
|
||||
loaded_template = cfg.templates('product/add')
|
||||
new_product = click.edit(loaded_template.render(grocy=data), extension='.yml')
|
||||
loaded_template = cfg.templates('product/create')
|
||||
created_product = click.edit(loaded_template.render(grocy=data), extension='.yml')
|
||||
|
||||
if not new_product:
|
||||
if not created_product:
|
||||
return
|
||||
|
||||
parsed_new_product = yaml.safe_load(new_product)
|
||||
parsed_created_product = yaml.safe_load(created_product)
|
||||
if template == 'debug':
|
||||
click.echo(parsed_new_product)
|
||||
click.echo(parsed_created_product)
|
||||
return
|
||||
entity = Entity(name='products')
|
||||
entity.create(parsed_new_product)
|
||||
entity.create(parsed_created_product)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise e
|
||||
@ -238,6 +237,30 @@ def recipe(ctx):
|
||||
pass
|
||||
|
||||
|
||||
@recipe.command()
|
||||
def create(template):
|
||||
logger = logging.getLogger('cli.recipe.create')
|
||||
try:
|
||||
cfg = Configuration()
|
||||
recipe = Entity(name='recipes')
|
||||
if template:
|
||||
loaded_template = cfg.templates(template)
|
||||
else:
|
||||
loaded_template = cfg.templates('recipe/create')
|
||||
created_recipe = click.edit(loaded_template.render(),
|
||||
extension='.yml')
|
||||
if created_recipe is None:
|
||||
return
|
||||
parsed_created_recipe = util.load_yaml(created_recipe)[0]
|
||||
|
||||
if template == 'debug':
|
||||
click.echo(parsed_created_recipe)
|
||||
return
|
||||
shopping_lists.create(parsed_created_recipe)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@recipe.command()
|
||||
@click.pass_context
|
||||
@click.argument('recipe_id', required=False)
|
||||
@ -736,3 +759,30 @@ def list(name, template):
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise e
|
||||
|
||||
|
||||
@chore.command()
|
||||
@click.option('-t', 'template')
|
||||
def create(template):
|
||||
logger = logging.getLogger('cli.chore.create')
|
||||
try:
|
||||
cfg = Configuration()
|
||||
cfg.load()
|
||||
entity = Entity(name='chores')
|
||||
if template:
|
||||
loaded_template = cfg.templates(template)
|
||||
else:
|
||||
loaded_template = cfg.templates('chore/create')
|
||||
created_chore = click.edit(loaded_template.render(), extension='.yml')
|
||||
|
||||
if not created_chore:
|
||||
return
|
||||
|
||||
parsed_created_chore = yaml.safe_load(created_chore)
|
||||
if template == 'debug':
|
||||
click.echo(parsed_created_chore)
|
||||
return
|
||||
entity.create(parsed_created_chore)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise e
|
||||
|
10
templates/chore/create.yml
Normal file
10
templates/chore/create.yml
Normal file
@ -0,0 +1,10 @@
|
||||
name:
|
||||
description: |-
|
||||
period_type: # Valid
|
||||
period_days:
|
||||
track_date_only:
|
||||
rollover:
|
||||
consume_product_on_execution:
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user