Giter VIP home page Giter VIP logo

clap-st's Introduction

clap — Command line argument parser for Pharo

Build Status Coverage Status

Named after and inspired by clap-rs, but this is an independent implementation.

Terminal screencast demo

Currently still in the initial implementation phase, meaning the main pieces are there but many features are still missing and may force changes in the design.

Loading instructions

starting from a Pharo image

Metacello new baseline: 'Clap';
    repository: 'github://cdlm/clap-st/src';
    load.

starting from the shell

git clone https://github.com/cdlm/clap-st.git
cd clap-st
curl get.pharo.org/alpha+vm | bash

…and then, in the image just downloaded, open a workspace and evaluate:

Metacello new baseline: 'Clap';
   repository: 'gitlocal://./src';
   load.

Shameless plug: I work with Fari and direnv to automate building and launching the development image:

# setup $PHARO
fari build
fari run

Defining and invoking commands

Commands and subcommands are instances of ClapCommand. To make a command accessible from the command line, return it from a class-side factory method with the <commandline> pragma. For instance, here's how we declare the traditional hello, world! example, with the actual behavior delegated the instance-side method ClapCommandLineExamples >> sayHello:

hello
	"The usual Hello-World example, demonstrating a Clap command with a couple options."
	<commandline>

	^ (ClapCommand withName: 'hello')
		description: 'Provides greetings';
		add: ClapFlag forHelp;
		add: ((ClapFlag withName: 'shout')
			description: 'Greet loudly');
		add: ((ClapPositional withName: 'who')
			description: 'Recipient of the greetings';
			defaultMeaning: [ 'world' ]);
		meaning: [ :args |
			args atName: 'help' ifFound: [ :help |
				help value.
				help context exitSuccess ].

			(self with: args) sayHello ]

For now, Clap installs itself as a named command line handler; e.g., to run the hello example command:

$PHARO_VM $PHARO_IMAGE clap hello
$PHARO_VM $PHARO_IMAGE clap hello --shout you

Commands can also be tested from within the image; running them from an interactive session will not quit the image, but any output from the command will still go to the standard output:

ClapCommandLineExamples hello
	runWith: #('hello' '--help').

Contributors

Many thanks to everyone who has contributed to clap in one way or another:

Clément Mastin, Damien Pollet, Rajula Vineet Reddy

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.