slackbuilder/app/SlackBuilder/CommandLine.hs

89 lines
2.7 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,
)
data SlackBuilderCommand
= CategoryCommand Text
| SlackBuildCommand Text Text
| CommitCommand Text Text
| ExistsCommand Text
| ArchiveCommand Text Text String Text
| DownloadCommand Text String
| CloneCommand Text Text Text
| DownloadAndDeployCommand Text Text
| Up2DateCommand
data PackagistArguments = PackagistArguments
{ vendor :: Text
, name :: Text
} deriving (Eq, Show)
data GhArguments = GhArguments
{ owner :: Text
, name :: Text
, transform :: Maybe Text
} deriving (Eq, Show)
data TextArguments = TextArguments
{ versionPicker :: Text -> Text
, textURL :: Text
}
slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "category" (info categoryCommand mempty)
<> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty)
<> command "archive" (info archiveCommand mempty)
<> command "download" (info downloadCommand mempty)
<> command "clone" (info cloneCommand mempty)
<> command "deploy" (info deployCommand mempty)
<> command "up2date" (info up2DateCommand mempty)
where
categoryCommand = CategoryCommand
<$> argument str (metavar "PKGNAM")
slackBuildCommand = SlackBuildCommand
<$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION")
commitCommand = CommitCommand
<$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION")
existsCommand = ExistsCommand <$> argument str (metavar "PATH")
archiveCommand = ArchiveCommand
<$> argument str (metavar "REPO")
<*> argument str (metavar "NAME_VERSION")
<*> argument str (metavar "TARBALL")
<*> argument str (metavar "TAG_PREFIX")
downloadCommand = DownloadCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARGET")
cloneCommand = CloneCommand
<$> argument str (metavar "REPO")
<*> argument str (metavar "TARBALL")
<*> argument str (metavar "TAG_PREFIX")
deployCommand = DownloadAndDeployCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARBALL")
up2DateCommand = pure Up2DateCommand