-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# todo | ||
|
||
## mvp | ||
1. DMC | ||
1. `dmc` | ||
2. Follow up on [#234](https://github.com/pcapriotti/optparse-applicative/pull/234) to remove '--' | ||
3. MORE TESTS for dm/dmc runtime | ||
|
||
## later | ||
0. --local flag to execute on local machine instead of docker-machine targets | ||
1. Use monad transformer to stack Sh on top of Either (error transformer) | ||
0. `--local` flag to execute on local machine instead of docker-machine targets | ||
1. Use monad transformer to stack `Sh` on top of `Either` (error transformer) | ||
2. Read up on exception handling link in haskell-fun-times resources |
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,82 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ExtendedDefaultRules #-} | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
module Main where | ||
|
||
-- Local packages | ||
import Dockmaster | ||
|
||
-- External packages | ||
import Shelly hiding (command) | ||
import Options.Applicative | ||
|
||
-- Base packages | ||
import Prelude hiding (FilePath) | ||
import Data.Monoid ((<>)) | ||
import qualified Data.Text as T | ||
|
||
default (T.Text) | ||
|
||
-- | Represents cli options/arguments | ||
data Dmc | ||
= Set SetOptions | ||
| Get GetOptions | ||
| Unshift SetOptions | ||
| Shift GetOptions | ||
| Push SetOptions | ||
| Pop GetOptions | ||
deriving (Eq, Show) | ||
|
||
-- | Arguments necessary for setting value | ||
data SetOptions = SetOptions | ||
{ sName :: String | ||
, sValue :: String | ||
} deriving (Eq, Show) | ||
|
||
-- | Arguments necessary for getting value or shifting/popping array | ||
data GetOptions = GetOptions | ||
{ gName :: String | ||
} deriving (Eq, Show) | ||
|
||
-- | Main runtime | ||
main :: IO () | ||
main = execParser opts >>= shelly . runtime | ||
|
||
-- | Runtime shell execution | ||
runtime :: Dmc -> Sh () | ||
runtime opts = undefined | ||
|
||
-- | Parser for /set/ commands | ||
setOptions :: Parser SetOptions | ||
setOptions = SetOptions | ||
<$> argument str (metavar "NAME" <> help "Name of the setting to modify") | ||
<*> argument str (metavar "VALUE" <> help "Value to add/set") | ||
|
||
-- | Parser for /get/ commands | ||
getOptions :: Parser GetOptions | ||
getOptions = GetOptions | ||
<$> argument str (metavar "NAME" <> help "Name of the setting to retrieve") | ||
|
||
-- | Parser for 'Dmc'. | ||
parser :: Parser Dmc | ||
parser = subparser | ||
( (command "set" $ commandInfo (Set <$> setOptions) "Set value") | ||
<> (command "get" $ commandInfo (Get <$> getOptions) "Get value") | ||
<> (command "unshift" $ commandInfo (Unshift <$> setOptions) "Unshift value (for arrays)") | ||
<> (command "shift" $ commandInfo (Shift <$> getOptions) "Shift value (for arrays)") | ||
<> (command "push" $ commandInfo (Push <$> setOptions) "Push value (for arrays)") | ||
<> (command "pop" $ commandInfo (Pop <$> getOptions) "Pop value (for arrays)") | ||
) | ||
|
||
-- | Generate 'ParserInfo' for 'Dmc'. | ||
opts :: ParserInfo Dmc | ||
opts = info (helper <*> parser) | ||
( fullDesc | ||
<> header "dmc - dockmaster configuration modifiers" | ||
) | ||
|
||
-- | Helper to generate subcommand parser info | ||
commandInfo :: Parser Dmc -> String -> ParserInfo Dmc | ||
commandInfo opts desc = info | ||
(helper <*> opts) | ||
(fullDesc <> progDesc desc) |
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