62 lines
1.6 KiB
Haskell
62 lines
1.6 KiB
Haskell
module SlackBuilder.CommandLine
|
|
( GhArguments(..)
|
|
, SlackBuilderCommand(..)
|
|
, PackagistArguments(..)
|
|
, TextArguments(..)
|
|
, slackBuilderParser
|
|
) where
|
|
|
|
import Data.Text (Text)
|
|
import Options.Applicative
|
|
( Parser
|
|
, ParserInfo(..)
|
|
, metavar
|
|
, argument
|
|
, str
|
|
, info
|
|
, fullDesc
|
|
, subparser
|
|
, command, optional
|
|
)
|
|
|
|
data SlackBuilderCommand
|
|
= PackagistCommand PackagistArguments
|
|
| TextCommand TextArguments
|
|
| GhCommand GhArguments
|
|
|
|
data PackagistArguments = PackagistArguments
|
|
{ vendor :: Text
|
|
, name :: Text
|
|
} deriving (Eq, Show)
|
|
|
|
data GhArguments = GhArguments
|
|
{ owner :: Text
|
|
, name :: Text
|
|
, transform :: Maybe 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")
|
|
|
|
ghArguments :: Parser GhArguments
|
|
ghArguments = GhArguments
|
|
<$> argument str (metavar "OWNER")
|
|
<*> argument str (metavar "NAME")
|
|
<*> optional (argument str (metavar "TRANSFORM"))
|
|
|
|
slackBuilderParser :: ParserInfo SlackBuilderCommand
|
|
slackBuilderParser = info slackBuilderCommand fullDesc
|
|
|
|
slackBuilderCommand :: Parser SlackBuilderCommand
|
|
slackBuilderCommand = subparser
|
|
$ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
|
|
<> command "text" (info (TextCommand <$> textArguments) mempty)
|
|
<> command "github" (info (GhCommand <$> ghArguments) mempty)
|