{- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. -} -- | Command line parser. module SlackBuilder.CommandLine ( SlackBuilderCommand(..) , slackBuilderParser ) where import Data.Text (Text) import Options.Applicative ( Parser , ParserInfo(..) , metavar , argument , helper , str , info , fullDesc , subparser , command , optional, progDesc ) data SlackBuilderCommand = CheckCommand | Up2DateCommand (Maybe Text) | InstalledCommand slackBuilderParser :: ParserInfo SlackBuilderCommand slackBuilderParser = info (helper <*> slackBuilderCommand) fullDesc slackBuilderCommand :: Parser SlackBuilderCommand slackBuilderCommand = subparser $ command "check" checkCommand <> command "up2date" up2DateCommand <> command "installed" installedCommand where checkCommand = info checkP $ progDesc "Check all configured slackbuilds for updates" checkP = pure CheckCommand up2DateP = Up2DateCommand <$> optional (argument str (metavar "PKGNAM")) up2DateCommand = info up2DateP $ progDesc "Update a single or multiple slackbuild in the configured repository" installedCommand = info installedP $ progDesc "Find local packages that can be updated using the configured repository" installedP = pure InstalledCommand