Giter VIP home page Giter VIP logo

clamp's Introduction

clamp

CLI Alias tool with variable substitution

This tool allows you to bind a string to a CLI command. It also allows for variable that are passed as cli parameters. This is really handy for testing an HTTP API by wrapping curl commands, for example:

$ clamp --set listusers -- 'curl --silent -H "Content-type: application/json" http://localhost:$(-port=3000)/users | python -m json.tool'

This will create a new clamp command called "listusers" that can accept a parameter "-port" for the port, although a default of 3000 is provided.

$ clamp listusers
[
    {
        "created_at": "2015-05-29T23:18:47.224Z",
        "email": "[email protected]",
        "id": 8,
        "name": "Eric",
        "updated_at": "2015-05-29T23:18:47.224Z"
    },
    {
        "created_at": "2015-05-29T23:34:43.583Z",
        "email": "sdjf",
        "id": 9,
        "name": "akdfh",
        "updated_at": "2015-05-29T23:34:43.583Z"
    }
]

Slightly more complicated, be careful with your quotes...

$ clamp --set adduser -- 'curl -X POST -H "Content-type: application/json" -d '"'"'{"name":"$(-name)","email":"$(-email)"}'"'"' http://localhost:$(-port=3000)/users'
$ clamp adduser -name Eric -email [email protected]
{"id":8,"name":"Eric","email":"[email protected]","created_at":"2015-05-29T23:18:47.224Z","updated_at":"2015-05-29T23:18:47.224Z"}

If the quotes get tricky, use the -r option to read from stdin

$ clamp -r --set adduser
curl -X POST -H "Content-type: application/json" -d '{"name":"$(-name)","email":"$(-email)"}' http://localhost:$(-port=3000)/users
$ ./clamp --list
adduser:  'curl -X POST -H "Content-type: application/json" -d '"'"'{"name":"$(-name)","email":"$(-email)"}'"'"' http://localhost:$(-port=3000)/users'
$

##Clamp options

$ clamp -h
usage: clamp [-h] [--version] [--set SET] [-r] [--list] [-n] [--delete {}] ...

CLAMP

positional arguments:
  command      user defined command: {}

optional arguments:
  -h, --help   show this help message and exit
  --version    show program's version number and exit
  --set SET    Create a new command
  -r           Read command from stdin instead of command line, may be easier
               for quotes
  --list       List commands
  -n           Don't escape commands when listing
  --delete {}  Delete command

Clamp will even show the usage for the commands you create, though it needs improvement:

$ clamp listusers --help
usage: clamp [-h] [-port PORT]

listusers

optional arguments:
  -h, --help  show this help message and exit
  -port PORT

##.clamp files Clamp will create a file in the current directory called .clamp where it will store the command alias. This allows you to create different clamp files for different projects.

##Install

$ sudo pip3 install git+https://github.com/seiferteric/clamp.git

# To enable command line completion

$ pip3 install argcomplete
$ activate-global-python-argcomplete3

Or build a Debian package (must have git-buildpackage installed)

$ ./clamp mk_deb
$ sudo dpkg -i ../clamp_<version>.deb

##TODO

  • Add input from STDIN for long text input
  • Fix tab completion for custom clamp commands.
  • Export command(s) as standalone scripts.

clamp's People

Contributors

seiferteric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.