Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clap — ESUG 2018

Damien Pollet
September 13, 2018

Clap — ESUG 2018

Clap is a command-line argument parser for Pharo

Github: https://github.com/cdlm/clap-st
Demo video: https://www.youtube.com/watch?v=VjnVZR4FMcQ

Damien Pollet

September 13, 2018
Tweet

More Decks by Damien Pollet

Other Decks in Programming

Transcript

  1. 3

  2. Damien sept. 2018 PHARO esug clap N+1 tool demo 4

    command- args line ommand ine
 rgument arser ommand ine
 rgument arser ommand ine
 rgument arser Command Line
 Argument Parser C L
 A P C L
 A P C L
 A P C L
 A P
  3. 6 github.com/cdlm/clap-st hello! I'm Damien Pollet RMOD team @ Inria

    Lille, France …and I teach Java… ! Use the command line?
 please talk to me! besides Clap: ·Coral (a looong time ago) ·LaTeX typography for the Pharo books ·fari.sh (image builder/runner)
  4. 12 2nd pos. 1st pos. sub-cmd sub-command command git -C

    dir remote add foo git@gith pos flag
  5. flow 13 feedback
 to user application
 domain Queries, meanings
 +


    validations specification (= grammar) activation (= syntax tree) command line
 (= words) specification (= grammar) activation (= syntax tree) command flag positional command line
 (= words) hello --shout foo context match mismatch implicit Queries, meanings
 +
 validations feedback
 to user application
 domain ! "
  6. 16 cmd := (ClapCommand withName: 'hello') description: 'Says hello'; add:

    param; add: (ClapFlag withName: 'shout'); meaning: [ :args | "# ] param := (ClapPositional withName: 'who') description: 'Recipient of greeting'; defaultMeaning: [ 'world' ].
  7. 19 context := (ClapContext specification: cmd) arguments: #('hello' 'esug'). "same

    + immediate evaluation:" cmd activateWith: #('hello' 'esug').
  8. context match. 20 context match atName: 'shout'. context match at:

    param. context match atName: 'who'. "a ClapPositionalMatch(esug)" "a ClapCommandMatch(hello esug)" "a ClapImplicit"
  9. give meaning 21 cmd meaning: [ :args | ]. "#

    42 "42" context match value. (context match atName: 'who') value. "esug" (context match atName: 'shout') value. "false"
  10. 22 cmd meaning: [ :args | | recipient | recipient

    := args atName: 'who'. args context stdout << 'hello ' , recipient value; lf ] match of CMD spec match of positional meaning of positional (implicit matches give default meaning)
  11. ClapCommandLineExamples class >> hello <commandline> ^ install 23 (ClapCommand withName:

    'hello') description: 'Says hello'; add: (ClapPositional withName: 'who') description: 'Recipient of greeting' defaultMeaning: [ 'world' ]. hello esug › ./pharo Pharo.image clap
  12. exit 25 context exitSuccess. Exit success signal. context exitFailure. context

    exit: 1. Exit failure signal. $ % "OK for interactive use (catches Exit)" cmd activateWith: #('hello' 'esug').
  13. help 26 ClapCommand forHelp. ClapFlag forHelp. git commit --help git

    help commit documents specified sibling, or parent runs automatically meaning: [ :args | args atName: 'help' ifFound: [ :help | help value; exitSuccess ]. documents parent requires explicit check
  14. validate 27 git -C dir remote add foo git@gith valid

    repo valid name valid URL ↺ work in progress…
  15. 29 github.com/cdlm/clap-st ✓ basic architecture ✓ workspace & commandline ✓

    pharo commands version & evaluate → more to port ↺ validations error handling & feedback → common meanings → Coral-like DSL → port fari.sh → shell completions…