slackbuilder/app/SlackBuilder/CommandLine.hs

92 lines
2.8 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 qualified Data.Text as Text
import Options.Applicative
( Parser
, ParserInfo(..)
, metavar
, argument
, str
, info
, fullDesc
, subparser
2023-10-13 19:34:02 +02:00
, command,
)
data SlackBuilderCommand
2023-10-03 18:53:41 +02:00
= TextCommand TextArguments
2023-08-15 10:33:19 +02:00
| SlackBuildCommand Text Text
| CommitCommand Text Text
| ExistsCommand Text
| ArchiveCommand Text Text String Text
2023-08-21 13:38:20 +02:00
| DownloadCommand Text String
2023-08-25 10:30:24 +02:00
| CloneCommand Text Text Text
2023-08-28 21:05:47 +02:00
| DownloadAndDeployCommand Text Text
2023-09-03 10:26:43 +02:00
| Up2DateCommand
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)
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
2023-10-03 18:53:41 +02:00
$ command "text" (info (TextCommand <$> textArguments) mempty)
2023-08-15 10:33:19 +02:00
<> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty)
<> command "archive" (info archiveCommand mempty)
2023-08-21 13:38:20 +02:00
<> command "download" (info downloadCommand mempty)
2023-08-25 10:30:24 +02:00
<> command "clone" (info cloneCommand mempty)
2023-08-28 21:05:47 +02:00
<> command "deploy" (info deployCommand mempty)
2023-09-03 10:26:43 +02:00
<> command "up2date" (info up2DateCommand mempty)
2023-08-15 10:33:19 +02:00
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")
2023-08-21 13:38:20 +02:00
downloadCommand = DownloadCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARGET")
2023-08-25 10:30:24 +02:00
cloneCommand = CloneCommand
<$> argument str (metavar "REPO")
<*> argument str (metavar "TARBALL")
<*> argument str (metavar "TAG_PREFIX")
2023-08-28 21:05:47 +02:00
deployCommand = DownloadAndDeployCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARBALL")
2023-09-03 10:26:43 +02:00
up2DateCommand = pure Up2DateCommand