47 lines
1.2 KiB
Haskell
47 lines
1.2 KiB
Haskell
|
module SlackBuilder.CommandLine
|
||
|
( SlackBuilderCommand(..)
|
||
|
, PackagistArguments(..)
|
||
|
, TextArguments(..)
|
||
|
, slackBuilderParser
|
||
|
) where
|
||
|
|
||
|
import Data.Text (Text)
|
||
|
import Options.Applicative
|
||
|
( Parser
|
||
|
, ParserInfo(..)
|
||
|
, metavar
|
||
|
, argument
|
||
|
, str
|
||
|
, info
|
||
|
, fullDesc
|
||
|
, subparser
|
||
|
, command
|
||
|
)
|
||
|
|
||
|
data SlackBuilderCommand
|
||
|
= PackagistCommand PackagistArguments
|
||
|
| TextCommand TextArguments
|
||
|
|
||
|
data PackagistArguments = PackagistArguments
|
||
|
{ vendor :: Text
|
||
|
, name :: Text
|
||
|
} deriving (Eq, Show)
|
||
|
|
||
|
newtype TextArguments = TextArguments Text
|
||
|
|
||
|
packagistArguments :: Parser PackagistArguments
|
||
|
packagistArguments = PackagistArguments
|
||
|
<$> argument str (metavar "VENDOR")
|
||
|
<*> argument str (metavar"NAME")
|
||
|
|
||
|
textArguments :: Parser TextArguments
|
||
|
textArguments = TextArguments <$> argument str (metavar "URL")
|
||
|
|
||
|
slackBuilderParser :: ParserInfo SlackBuilderCommand
|
||
|
slackBuilderParser = info slackBuilderCommand fullDesc
|
||
|
|
||
|
slackBuilderCommand :: Parser SlackBuilderCommand
|
||
|
slackBuilderCommand = subparser
|
||
|
$ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
|
||
|
<> command "text" (info (TextCommand <$> textArguments) mempty)
|