unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* guile-config: How do I use a <codex>?
@ 2020-01-15 19:13 sirgazil
  2020-01-15 21:08 ` Alex Sassmannshausen
  0 siblings, 1 reply; 3+ messages in thread
From: sirgazil @ 2020-01-15 19:13 UTC (permalink / raw)
  To: Guile User

I designed the following CLI for an example program that pretends to control irrigation sprinklers.

  $ sprinklers
  Display some information about the sprinklers in the farm.

  $ sprinklers start-all
  All sprinklers started.

  $ sprinklers stop-all
  All sprinklers stopped.

  $ sprinklers start A5
  Sprinkler A5 started.

  $ sprinklers stop A5
  Sprinkler A5 stopped.

All subcommands accept a --oscillate flag. For example:

  $ sprinklers start --oscillate A5
  Sprinkler A5 started in oscillation mode.

I'm trying out guile-config to declare the CLI of the program using a <configuration> record (https://gitlab.com/sirgazil/guile-lab/blob/master/scripts/cli/sprinklers#L96) and I have defined a "dispatcher" procedure that is supposed to run some Guile procedure depending on the command entered by the user (https://gitlab.com/sirgazil/guile-lab/blob/master/scripts/cli/sprinklers#L165). But I don't understand how to use the <codex> record for that purpose (I'm currently matching command patterns against the result of (command-line) instead to make the example program work).

So, for example, using the <codex> record, how would I map the following command

  $ sprinklers start A5

to a Guile procedure like

  (define (sprinkler-start id) ...)


Thanks,

---
https://sirgazil.bitbucket.io/







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: guile-config: How do I use a <codex>?
  2020-01-15 19:13 guile-config: How do I use a <codex>? sirgazil
@ 2020-01-15 21:08 ` Alex Sassmannshausen
  2020-01-15 23:18   ` sirgazil
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Sassmannshausen @ 2020-01-15 21:08 UTC (permalink / raw)
  To: guile-user

Hi!

sirgazil <sirgazil@zoho.com> writes:

> […]
>
> I'm trying out guile-config to declare the CLI of the program using a
> <configuration> record
> (https://gitlab.com/sirgazil/guile-lab/blob/master/scripts/cli/sprinklers#L96)

You can actually make use of config's inheritance here, because
oscillate is shared by all subcommands.  You can specify oscillate in
the top-level command and then use the (wanted …) property of each
subcommand <configuration> object to say you would like to inherit
oscillate from its parent.  I think this one is documented correctly in
the manual! :-)

> […]
>
> So, for example, using the <codex> record, how would I map the following command
>
>   $ sprinklers start A5
>
> to a Guile procedure like
>
>   (define (sprinkler-start id) ...)

I think this is one place for the documentation of config let you down!

The procedure you want to use here is (full-command <codex>). This will
give you a list of string elements, each being a "breadcrumb" down the
trail of subcommands.

This is how I tend to use it:

(match (full-command options)  ; options is a <codex>
  ((_ "start")
   (sprinkler-start (option-ref options '(id))))  ; id is arg, not key
   …)

Hth,

Alex



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: guile-config: How do I use a <codex>?
  2020-01-15 21:08 ` Alex Sassmannshausen
@ 2020-01-15 23:18   ` sirgazil
  0 siblings, 0 replies; 3+ messages in thread
From: sirgazil @ 2020-01-15 23:18 UTC (permalink / raw)
  To: alexsassmannshausen; +Cc: guile-user

 ---- On Wed, 15 Jan 2020 16:08:51 -0500 Alex Sassmannshausen <alex.sassmannshausen@gmail.com> wrote ----
 > Hi!
 > 
 > sirgazil <sirgazil@zoho.com> writes:
 > 
 > > […]
 > >
 > > I'm trying out guile-config to declare the CLI of the program using a
 > > <configuration> record
 > > (https://gitlab.com/sirgazil/guile-lab/blob/master/scripts/cli/sprinklers#L96)
 > 
 > You can actually make use of config's inheritance here, because
 > oscillate is shared by all subcommands.  You can specify oscillate in
 > the top-level command and then use the (wanted …) property of each
 > subcommand <configuration> object to say you would like to inherit
 > oscillate from its parent.  I think this one is documented correctly in
 > the manual! :-)

Yeah, I thought about it, but running "sprinklers --help" displayed the "--oscillate" flag as an option of the "sprinklers" command too, which is actually not what I wanted...


 > > […]
 > >
 > > So, for example, using the <codex> record, how would I map the following command
 > >
 > >   $ sprinklers start A5
 > >
 > > to a Guile procedure like
 > >
 > >   (define (sprinkler-start id) ...)
 > 
 > I think this is one place for the documentation of config let you down!
 > 
 > The procedure you want to use here is (full-command <codex>). This will
 > give you a list of string elements, each being a "breadcrumb" down the
 > trail of subcommands.

Oh, right, the "full-command" procedure is not documented in the manual.


 > This is how I tend to use it:
 > 
 > (match (full-command options)  ; options is a <codex>
 >   ((_ "start")
 >    (sprinkler-start (option-ref options '(id))))  ; id is arg, not key
 >    …)
 
Thank you Alex, that solves, my problem :)







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-15 23:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 19:13 guile-config: How do I use a <codex>? sirgazil
2020-01-15 21:08 ` Alex Sassmannshausen
2020-01-15 23:18   ` sirgazil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).