dnaeon / clingon

Command-line options parser system for Common Lisp
Other
122 stars 7 forks source link

[SBCL] --help and --version print SBCL's help and version #5

Closed alessiostalla closed 1 year ago

alessiostalla commented 1 year ago

Clingon says that you can provide --help or --version options:

./portofino                                                                                                   ~/projects/portofino-cli 64 ↵ 
Usage: 

NAME:
  portofino - The Portofino CLI

USAGE:
  portofino [global-options] [<command>] [command-options] [arguments ...]

OPTIONS:
      --help              display usage information and exit
      --version           display version and exit
[...]

However, at least on SBCL, it seems Clingon doesn't intercept them for the top-level command:

$ ./portofino --version
SBCL 2.1.6
$ ./portofino --help 
Usage: sbcl [runtime-options] [toplevel-options] [user-options]
[...]
dnaeon commented 1 year ago

Hey @alessiostalla ,

Can you please provide a short example I can run and try to reproduce?

How did you build the binary?

Can you build the clingon.demo app and see if that works as expected?

Thanks!

alessiostalla commented 1 year ago

Hi, thanks, the example is here: https://github.com/alessiostalla/portofino-cli#installation

I'll try building the clingon.demo app and report to you asap!

dnaeon commented 1 year ago

I've quickly looked at the ASDF system for portofino, and the issue I think you are having is because of this line.

https://github.com/alessiostalla/portofino-cli/blob/master/src/binary-sbcl.lisp#L5

Try removing the SAVE-LISP-AND-DIE from there.

Also, I've made these changes to your ASDF system (note the :build-operation, :build-pathname and :entry-point).

(defsystem "portofino-cli/executable"
  :version "0.2.0"
  :author "Alessio Stalla"
  :license "AGPL"
  :depends-on ("portofino-cli")
  :components ((:module "src" :components ((:file "binary-sbcl"))))
  :build-operation "program-op"
  :build-pathname "bin/portofino-cli"
  :entry-point "portofino-cli:main"
  :description "Command-line interface to a Portofino application")

A simple Makefile to make things easier to build.

LISP ?= sbcl

cli:
        ${LISP} --eval '(ql:quickload :portofino-cli/executable)' \
                --eval '(asdf:make :portofino-cli/executable)' \
                --eval '(quit)'

.PHONY: cli

And here's the final CLI.

> bin/portofino-cli --help
NAME:
  portofino - The Portofino CLI

USAGE:
  portofino [global-options] [<command>] [command-options] [arguments ...]

OPTIONS:
      --help              display usage information and exit
      --version           display version and exit
  -U, --url <VALUE>       URL of the Portofino application [env: $PORTOFINO_URL]
  -p, --password <VALUE>  password to log in
  -u, --username <VALUE>  username to log in

COMMANDS:
  new     Create a new Portofino project
  action  Commands for working with resource-actions
  db      Commands for working with databases
  login   Login to a running Portofino instance
  logout  Log out of the application, i.e. delete the stored authentication
          token

AUTHORS:
  Alessio Stalla <alessiostalla@gmail.com>

One final thing you need to take care of is to add :version to your command, because currently it doesn't have one.

alessiostalla commented 1 year ago

I can confirm it works :)