slackbuilder/app/SlackBuilder/CommandLine.hs

62 lines
1.6 KiB
Haskell
Raw Normal View History

module SlackBuilder.CommandLine
2023-08-09 20:59:42 +02:00
( GhArguments(..)
, SlackBuilderCommand(..)
, PackagistArguments(..)
, TextArguments(..)
, slackBuilderParser
) where
import Data.Text (Text)
import Options.Applicative
( Parser
, ParserInfo(..)
, metavar
, argument
, str
, info
, fullDesc
, subparser
2023-08-10 12:47:43 +02:00
, command, optional
)
data SlackBuilderCommand
= PackagistCommand PackagistArguments
| TextCommand TextArguments
2023-08-09 20:59:42 +02:00
| GhCommand GhArguments
data PackagistArguments = PackagistArguments
{ vendor :: Text
, name :: Text
} deriving (Eq, Show)
2023-08-09 20:59:42 +02:00
data GhArguments = GhArguments
{ owner :: Text
, name :: Text
2023-08-10 12:47:43 +02:00
, transform :: Maybe Text
2023-08-09 20:59:42 +02:00
} 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")
2023-08-09 20:59:42 +02:00
ghArguments :: Parser GhArguments
ghArguments = GhArguments
<$> argument str (metavar "OWNER")
<*> argument str (metavar "NAME")
2023-08-10 12:47:43 +02:00
<*> optional (argument str (metavar "TRANSFORM"))
2023-08-09 20:59:42 +02:00
slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
<> command "text" (info (TextCommand <$> textArguments) mempty)
2023-08-09 20:59:42 +02:00
<> command "github" (info (GhCommand <$> ghArguments) mempty)