Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement how command line interface using Glcmd #107

Open
leovalais opened this issue Dec 13, 2018 · 2 comments
Open

Implement how command line interface using Glcmd #107

leovalais opened this issue Dec 13, 2018 · 2 comments

Comments

@leovalais
Copy link
Contributor

leovalais commented Dec 13, 2018

The key to make html_of_wiki a decent and usable tool is to polish its user interface. Currently users have to deal with shell scipts (poorly tested and documented, with too little error management 👎) such as dop and quickdop. They were meant to make html_of_wiki quickly usable of Ocsigen but not for other end users.

Thus, implement an OCaml 🐫 program, how, which re-implements all the features of both dop and quickdop and get rid of these crappy scripts (:+1:). A modern and popular command line interface is the sub-command system that git uses. Here is a list of the features how has to implement (in combination with #106, this is an extract of a draft design file---please pay no attention to the format):

- ~how~ :: alias pour ~how help~
- ~how help~ :: affiche la liste des commandes de premier niveau
  - ~how help CMD~ :: affiche l'aide de la ~CMD~ donnée
- ~how init~ :: crée dans le dossier courant un fichier ~how.yml~ contenant une configuration par défaut
  - ~how init infer~ :: la configuration est déduite à partir de l'examen du dossier
  - ~how init default~ :: comme ~how init~
- ~how config~ :: == ~how config help~
  - ~how config help~ :: affiche l'aide de chaque option de configuration
  - ~how config check~ :: vérifie la validité de la configuration (pas de dossier n'existant pas)
  - ~how config infer~ :: affiche une configuration minimale déduite
- ~how build [-d DIR] [VERSIONS...]~ :: compile les versions données (ou toutes si aucune n'est donnée) dans ~DIR |? _build~
- ~how deploy [-d DIR] [-m MSG] [-r REPO]~ :: déploie le site sur GHPages (override l'option ~deploy~) et commit avec le ~MSG~ donné dans le ~REPO~ donné (~upstream~ par défaut). Échoue si le cwd n'est pas un dépôt git.
- ~how check~ :: fais tous les checks
  - ~how check links [-d DIR] [-r|--raw] [-s|--silent]~ :: vérifie les liens morts du ~DIR~ et sort sur stderr le json. Si ~raw~ est donné sort directement l'output de linkchecker.
  - ~how check config~ :: == ~how config check~

To implement all that complex argv parsing, the module Glcmd (Git-Like CoMmanDs) has been designed (see #88). It helps to express declaratively what options each sub-command takes and does the parsing all by itself. Here is what has already been implemented:

html_of_wiki/src/how.ml

Lines 119 to 155 in e4314fd

let how_commandline =
Glcmd.[anonymous help_cmd ~doc:"Displays available commands";
command "help" help_cmd
~args:[multiple String ~valname:"CMD" ~doc:"The command to describe."]
~doc:"Displays help for a given command.";
command "build" (printr "build")
~args:[arg "dir" String `Dir ~short:"d" (*~default:"_build"*) ~valname:"DIR"
~doc:"The directory to build in.";
multiple File ~valname:"VERSION" ~doc:"The versions of the documentation to build."]
~doc:"Build the documentation of the project.";
prefix "check"
[anonymous (printr "check all") ~doc:"Perform all checks.";
command "links" (printr "check links")
~args:[arg "dir" File `Dir ~short:"d" ~valname:"DIR"
~doc:"The directory to check in.";
flag "raw" `Raw ~short:"r"
~doc:"Prints the raw output of [linkchecker] (ie. no Json formatting).";
flag "silent" `Silent ~short:"s"
~doc:"Perform the check but outputs nothing."]
~doc:"Run [linkchecker] on the build directory to check for deadlinks.";
command "config" (printr "check config")
~doc:"Checks the validity of the configuration file."];
prefix "config"
[anonymous (printr "config help") ~doc:"Configuration file related commands.";
command "help" config_help_cmd
~doc:"Lists the available configuration options";
command "check" (printr "check config")
~doc:"Checks the validity of the configuration file.";
command "infer" (printr "inferring.")
~doc:"Prints a minimal configuration inferred using the structure of the current directory."];
prefix "init"
[anonymous (printr "init")
~doc:"Creates an inferred configuration file in the current directory.";
command "infer" (printr "init infer")
~doc:"Creates an inferred configuration file in the current directory.";
command "default" (printr "init default")
~doc:"Creates a default configuration file in the current directory."]]

@hhugo
Copy link
Member

hhugo commented Jan 31, 2019

Glcmd sound very similar to Core.Command

@leovalais
Copy link
Contributor Author

I didn't know about Core.Command. This PR is an experiment to give how the same command line interface as Git, with verbs and parameters. Glcmd (the library ohow uses) doesn't support such verbs.

This issue isn't really important unless html_of_wiki is to be used by many unexperienced people, which isn't currently the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants