Search code examples
pythonpyinvoke

Passing string to Invoke


I am trying to use invoke to set up a basic git routine. The problem I am running into is that I cannot seem to get invoke to take a string as an argument parameter. I get an error everytime I run the code. I am sure I am missing something simple. I am running using ZSH.

Any help would be greatly appreciated!

(stats) bnice5000@Macbook COVID-STATS % invoke push --message='fixed invoke'  
fatal: paths 'invoke ...' with -a does not make sense
(stats) bnice5000@Macbook COVID-STATS % 
from invoke import task
import datetime

foldername = '{:%Y%m%d}'.format(datetime.date.today())
commit_message = '\"Daily push for {0}\"'.format(foldername)

@task
def push(c, tag=False, message=''):
    c.run('git add --all')
    if not message:
        message = commit_message
    c.run('git commit -am {0}'.format(message))
    if tag:
        c.run('git tag {0}'.format(foldername))

    c.run('git push origin master')


Solution

  • First: you can use print() instead of c.run() to see what command you run.

    You have to add " " in git commit -am "{0}" because you have message with space.

    Or you have to use " " inside ' ' in --message='"fixed invoke"'