slackbuilder/app/SlackBuilder/CommandLine.hs

92 lines
2.8 KiB
Haskell

module SlackBuilder.CommandLine
( GhArguments(..)
, SlackBuilderCommand(..)
, PackagistArguments(..)
, TextArguments(..)
, slackBuilderParser
) where
import Data.Text (Text)
import qualified Data.Text as Text
import Options.Applicative
( Parser
, ParserInfo(..)
, metavar
, argument
, str
, info
, fullDesc
, subparser
, command,
)
data SlackBuilderCommand
= TextCommand TextArguments
| 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
}
textArguments :: Parser TextArguments
textArguments = TextArguments Text.strip
<$> argument str (metavar "URL")
slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "text" (info (TextCommand <$> textArguments) 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
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