Skip to content

Template for a Python CLI that can be built into a WHL file for distribution

Notifications You must be signed in to change notification settings

FoodyFood/python-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python CLI

This Python CLI template doesn't do very much, it just prints out text, but you can fill in the blanks and add to it.

The CLI, once built and installed, can be called form anywhere in the system to perform tasks. You can hook it into AWS CLI using subprocess.call. You could have it sort or write files. Have it bring up or down infrastructure to save money. And anything else you can do from a CLI, but want wrapped for simplicity, accessability, or to save time.

Example Screenshots

Python CLI has a built in help command that lists all commands

help-commmand

An example of using it to create some resource using a template

create-bucket

Using it to stop a server

stop-server

Running Commands

For testing the commands you build, you can call them like this. This will save you rebuilding the WHL file each time to to test something

Bash

python3 -m python_cli:main <args>
python3 -m python_cli:main start -n server1 -m "start reason"

Windows

python -m python_cli:main <args>
python -m python_cli:main start -n server1 -m "start reason"


Build And Install The WHL

You can build the CLI into a WHL file and install it to be called from anywhere on your system

These commands are made for a bash terminal. To run on windows change pip3 to pip, and python3 to python

Building will require you to have setuptools and wheel isntalled

pip3 install setuptools wheel
make build
make install

Once the WHL is installed you can call it directly from your CLI (terminal or powershell)

python_cli start -n server1 -m "starting server to spend money"
python_cli stop -n server2 -m "stopping server to save money"


List Of Commands

This is the complete list of commands available in the template

python_cli create server -u "FoodyFood"
python_cli create bucket -n "bucket-123"

python_cli start -n "server1" -m "I started this to spend money"
python_cli stop -n "server2" -m "I stopped this to save money"

python_cli delete server -u "FoodyFood"
python_cli delete bucket -n "bucket-456" -u "FoodyFood"


Possible Issue

You may need to add your python site packages folder to your PATH variable

On Linux it would look like this

export PATH="$HOME/<username>/.local/bin:$PATH"

About

Template for a Python CLI that can be built into a WHL file for distribution

Topics

Resources

Stars

Watchers

Forks