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

Clap — ESUG 2018

Bc94d333458fb73f6249278982ba2f0a?s=47 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

Bc94d333458fb73f6249278982ba2f0a?s=128

Damien Pollet

September 13, 2018
Tweet

More Decks by Damien Pollet

Other Decks in Programming

Transcript

  1. CLAP

  2. 3

  3. 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
  4. demo 5

  5. 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)
  6. what 7

  7. 8 hello command

  8. 9 'foo' hello positional

  9. 10 'foo' --shout hello positional flag command

  10. 11 'foo' --shout hello positional flag --repeat 42 flag command

    pos.
  11. 12 2nd pos. 1st pos. sub-cmd sub-command command git -C

    dir remote add foo git@gith pos flag
  12. 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 ! "
  13. how 14

  14. specify 15 Positional Flag Command aliases Parameterized name description meaning

    defaultMeaning validations Parameter
  15. 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' ].
  16. activate args parent spec SubExpression Implicit word Explicit Parameter Expression

    ···Match Context
  17. 18 parent match atName:'shout' Context #(hello esug) Command hello Positional

    esug atName:'who' Implicit context parent
  18. 19 context := (ClapContext specification: cmd) arguments: #('hello' 'esug'). "same

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

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

    42 "42" context match value. (context match atName: 'who') value. "esug" (context match atName: 'shout') value. "false"
  21. 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)
  22. 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
  23. more 24

  24. 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').
  25. 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
  26. validate 27 git -C dir remote add foo git@gith valid

    repo valid name valid URL ↺ work in progress…
  27. hack 28

  28. 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…
  29. fin 30

  30. IBM Plex fonts Clapping Music Pharo postcard Coral slides Clap

    demo (YouTube)