module Main where import Data.Text (pack) import Options.Applicative import Types data Options = Options { from :: Source, to :: Destination } deriving (Eq, Ord, Show) longShort :: HasName f => String -> Mod f a longShort t@(c : _) = long t <> short c longShort t = long t options :: Parser Options options = Options <$> (sourceSpec <|> source) <*> (destinationSpec <|> destination) where sourceSpec = option (maybeReader (sourceFromText . pack)) ( longShort "from" <> help "Source to migrate from in the form of 'FORGE:USER'" ) source = Source <$> forge <*> fromUser forge = option (str >>= (pure . forgeFromText . pack)) ( long "forge" <> help "Forge to migrate from" ) fromUser = mkUser <$> strOption ( long "from-user" <> help "User account to migrate from" ) destinationSpec = option (maybeReader (destinationFromText . pack)) ( longShort "to" <> help "Destiation to migrate to in the form of 'GITEA_URL:USER'" ) destination = Destination <$> gitea <*> toUser gitea = option (str >>= (pure . mkGitea . pack)) ( longShort "gitea-url" <> help "URL of the Gitea instance to migrate to" ) toUser = mkUser <$> strOption ( long "to-user" <> help "User account to migrate to" ) main :: IO () main = do args <- execParser parser print args where parser = info (options <**> helper) ( fullDesc <> progDesc "migrate-to-gitea solves the problem wherein you have just spun up a new self-hosted https://gitea.io instance, and now you want to move your project history there (or perhaps to one of the more well known public instances)." <> header "migrate-to-gitea - cli tool to migrate from git{hub,lab} to a gitea instance" )