commander-cli: A command line argument/option parser library built around a monadic metaphor

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

A command line argument/option parser library built around a monadic metaphor.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.2.0.0, 0.2.0.1, 0.3.0.0, 0.4.0.0, 0.4.0.1, 0.4.1.1, 0.4.1.2, 0.5.0.0, 0.6.0.0, 0.6.1.0, 0.6.2.0, 0.7.0.0, 0.8.0.0, 0.9.0.0, 0.10.0.0, 0.10.0.1, 0.10.1.0, 0.10.1.1, 0.10.1.2, 0.10.1.3, 0.10.2.0, 0.11.0.0
Change log CHANGELOG.md
Dependencies base (>=4.13.0.0 && <4.14), commander-cli (>=0.1 && <0.2), mtl (>=2.2.2 && <2.3), text (>=1.2.4.0 && <1.3), unordered-containers (>=0.2.10.0 && <0.3) [details]
License MIT
Copyright 2019 Samuel Schlesinger
Author Samuel Schlesinger
Maintainer sgschlesinger@gmail.com
Category System, CLI, Options, Parsing
Home page https://github.com/SamuelSchlesinger/commander-cli
Uploaded by sgschlesinger at 2020-02-20T07:05:35Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for commander-cli-0.1.0.0

[back to package description]

Commander

The commander package contains two DSLs for describing command line programs, one at the type level and one at the term level. The one at the type level looks like this:

type File = "writer" & Arg "file" FilePath & Arg "contents" FilePath Raw
          + "reader" & Arg "file" FilePath & Raw

This is a type which encodes information about an command line program we want to write. We can instantiate a term of this type by writing

file :: ProgramT File IO
file = sub (arg \file -> arg \contents -> raw $ writeFile file contents) 
   :+: sub (arg \file -> raw $ readFile file >>= putStrLn)

I can write a term of this type without specifying the File type by using the TypeApplications extension.

file = sub @"writer" (arg @"file" \file -> arg @"contents" \contents -> raw $ writeFile file contents)
   :+: sub @"reader" (arg @"file" \file -> raw $ readFile file >>= putStrLn)

The library consists of a few basic types which are important for understanding how to use it. The first thing is the class

class Unrender r where
  unrender :: Text -> Maybe r

This class is what you will use to define the parsing of a type from text and can use any parsing library or whatever you want. Next, we have the class

class HasProgram p where
  data ProgramT p m a
  run :: ProgramT p IO a -> CommanderT State IO a
  hoist :: (forall x. m x -> n x) -> ProgramT p m a -> ProgramT p n a
  invocations :: [Text]

Instances of this class will define a syntactic element, a new instance of the data family ProgramT, as well as its semantics in terms of the CommanderT monad, which is a backtracking monad based on a metaphor to military commanders which retreats upon defeat.