ocsigen / html_of_wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement how command line interface using Glcmd

leovalais opened this issue · comments

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."]]

commented

Glcmd sound very similar to Core.Command

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.