This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to spec implicitly (fix #72)
WARN: this is a minor breaking change in that the spec serializes slightly different now. Option-aliases are serialized into a more friendly format, i.e. "-f" and "--foo" as opposed to the more simple, yet more verbose `{ type: "long", name: "foo" }`.
- Loading branch information
Showing
9 changed files
with
175 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{- | ||
Insert implicit flags into the specification. | ||
This ensures that e.g. `prog -v` or `prog -h` are always valid applications of | ||
the program. | ||
To do so, we quite simply add an extra usage top-level branch to the | ||
specification: `[-h] [-v]`. | ||
-} | ||
|
||
module Neodoc.Solve.ImplicitFlags where | ||
|
||
import Prelude | ||
import Data.NonEmpty | ||
import Neodoc.Spec | ||
import Neodoc.Data.Layout | ||
import Neodoc.Data.SolvedLayout | ||
import Neodoc.Solve.Error | ||
import Data.Array as A | ||
import Data.String as String | ||
import Data.Either (Either) | ||
import Data.List ((:), List(Nil), fromFoldable, catMaybes) | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Traversable (for, traverse) | ||
import Neodoc.OptionAlias (OptionAlias) | ||
import Neodoc.OptionAlias as OptionAlias | ||
|
||
implicitFlags | ||
:: List OptionAlias | ||
-> Spec SolvedLayout | ||
-> Either SolveError (Spec SolvedLayout) | ||
implicitFlags flags (Spec (spec@{ layouts: x:|xs })) = pure $ | ||
let y = toOption <$> fromFoldable flags | ||
in case y of | ||
Nil -> Spec spec { layouts = x :| xs } | ||
z:zs -> Spec spec { layouts = (pure $ z :| zs) :| x : xs } | ||
where | ||
toOption a = Group true true (((Elem $ Option a Nothing true):|Nil):|Nil) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters