python-click

python click help formatting newline

时间秒杀一切 提交于 2019-12-06 03:09:58
问题 I am seeing that a newline is not being preserved in my EPILOG? I want to know why if I see that newline remains only when a line has 74 characters? # http://click.pocoo.org/5/commands/ import click, sys def main_caller(*args, **kwargs): print('act on arguments', args, kwargs) EPILOG = ''' # oneline # twoline \n # oneline with 74char x # twoline with 74char x ''' @click.group(help='wwwwwwwwww', epilog=EPILOG, invoke_without_command=True, chain=True) @click.argument('start_or_stop') @click

How to build interactive menu for command-line application in python? [closed]

拟墨画扇 提交于 2019-12-06 00:30:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I've been working with click to make a command line program. Right now I'm implementing interactive menus in a very textual way. for example: 1-option #1 2-option #2 Enter the index of the option you want to select: But I would love to do this in a more elegant and interactive way. For example, I love the way

Is it possible to add a global argument for all subcommands in Click based interfaces?

余生长醉 提交于 2019-12-05 06:06:00
I am using Click under a virtualenv and use the entry_point directive in setuptools to map the root to a function called dispatch. My tool exposes two subcommands serve and config , I am using an option on the top level group to ensure that the user always passes a --path directive. However the usage turns out as follows: mycommand --path=/tmp serve both the serve and config sub commands need to ensure that the user always passes a path in and ideally I would like to present the cli as: mycommand serve /tmp` or `mycommand config validate /tmp current Click based implemenation is as follows: #

Pyinstaller on a setuptools package

五迷三道 提交于 2019-12-05 01:31:53
I'm attempting to run PyInstaller on a CLI app I am building in Python using the Click library. I'm having trouble building the project using PyInstaller. PyInstaller has a document in their GitHub wiki titled Recipe Setuptools Entry Point , which gives information about how to use PyInstaller with a setuptools package, which I'm using for this project. However, it seems it cannot find the base module when I run pyinstaller --onefile main.spec . My question is: Is the problem simply an issue with the folder structure I have? Does the Recipe Setuptools Entry Point assume a certain file

Use Flask's Click CLI with the app factory pattern

被刻印的时光 ゝ 提交于 2019-12-04 09:28:35
问题 I define my Flask application using the app factory pattern. When using Flask-Script, I can pass the factory function to the Manager . I'd like to use Flask's built-in Click CLI instead. How do I use the factory with Click? My current code uses Flask-Script. How do I do this with Click? from flask import Flask from flask_script import Manager, Shell def create_app(): app = Flask(__name__) ... return app manager = Manager(create_app) def make_shell_context(): return dict(app=app, db=db, User

Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment

不羁的心 提交于 2019-12-04 08:52:07
问题 I downloaded Quokka Python/Flask CMS to a CentOS7 server. Everything works fine with command sudo python3 manage.py runserver --host 0.0.0.0 --port 80 Then I create a file /etc/init.d/quokkacms. The file contains following code start() { echo -n "Starting quokkacms: " python3 /var/www/quokka/manage.py runserver --host 0.0.0.0 --port 80 touch /var/lock/subsys/quokkacms return 0 } stop() { echo -n "Shutting down quokkacms: " rm -f /var/lock/subsys/quokkacms return 0 } case "$1" in start) start

Commands with multiple common options going into one argument using custom decorator

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:44:53
I would like to make a module that makes it very simple to build click commands that share a lot of options. Those options would be distilled into a single object that is passed into the command. As an illustrative example: from magic import magic_command import click @magic_command('Colored') @click.option('--color') def cmd(magic, color): pass The total command would then have many --magic-... options that go into the magic object passed into cmd . I was able to achieve that using the following: def magic_command(name): def decorator(func): @click.option('--magic-foo') @click.option('--magic

Using Boolean Flags in Python Click Library (command line arguments)

心不动则不痛 提交于 2019-12-04 01:46:30
I'm trying to make a verbose flag for my Python program. Currently, I'm doing this: import click #global variable verboseFlag = False #parse arguments @click.command() @click.option('--verbose', '-v', is_flag=True, help="Print more output.") def log(verbose): global verboseFlag verboseFlag = True def main(): log() if verboseFlag: print("Verbose on!") if __name__ == "__main__": main() It'll never print "Verbose on!" even when I set the '-v' argument. My thoughts are that the log function needs a parameter, but what do I give it? Also, is there a way to check whether the verbose flag is on

Is it possible to reuse python @click.option decorators for multiple commands?

岁酱吖の 提交于 2019-12-03 16:57:52
问题 I have two Python CLI tools which share a set of common click.options. At the moment, the common options are duplicated: @click.command() @click.option('--foo', is_flag=True) @click.option('--bar', is_flag=True) @click.option('--unique-flag-1', is_flag=True) def command_one(): pass @click.command() @click.option('--foo', is_flag=True) @click.option('--bar', is_flag=True) @click.option('--unique-flag-2', is_flag=True) def command_two(): pass Is it possible to extract the common options in to a

Freeze a program created with Python's `click` pacage

瘦欲@ 提交于 2019-12-03 14:02:53
问题 I've got a command line program that uses Python's click package. I can install and run it locally, no problem with: pip install --editable . # (or leave out the editable of course) Now, I'd like to create an executable file that can be distributed and run standalone. Typically, since I'm in a Windows environment, I would use one of py2exe , pyinstaller or cx_Freeze . However, none of these packages work. More specifically, they all generate an executable, but the executable does nothing. I