Skip to content

Commit

Permalink
Stubbing out dmc cli
Browse files Browse the repository at this point in the history
  • Loading branch information
samtay committed Dec 15, 2016
1 parent dd60b52 commit d7f7c03
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
8 changes: 5 additions & 3 deletions TODO.md
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
82 changes: 82 additions & 0 deletions app/Dmc.hs
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)
11 changes: 11 additions & 0 deletions dockmaster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ executable dm
, optparse-applicative
default-language: Haskell2010

executable dmc
hs-source-dirs: app
main-is: Dmc.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, dockmaster
, shelly
, text
, optparse-applicative
default-language: Haskell2010

test-suite dockmaster-test
type: exitcode-stdio-1.0
hs-source-dirs: test
Expand Down

0 comments on commit d7f7c03

Please sign in to comment.