I've been trying to build a command line parser with Turtle, nothing fancy: https://github.com/Tyrn/go-procr
#!/usr/bin/env stack
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Turtle
import Prelude hiding (FilePath)
parserSwitch :: Parser (Bool, Bool)
parserSwitch = (,) <$> switch "verbose" 'v' "Unless verbose, just progress bar is shown"
<*> switch "filetitle" 'f' "Use file name for title tag"
parserArg :: Parser (FilePath, FilePath)
parserArg = (,) <$> argPath "src" "Source directory"
<*> argPath "dst" "Destination directory"
main :: IO ()
main = do
(verbose, filetitle) <- options "Flags" parserSwitch
echo (format ("verbose: "%w) verbose)
echo (format ("filetitle: "%w) filetitle)
(src, dst) <- options "Args" parserArg
echo (format ("src: "%fp) src)
echo (format ("dst: "%fp) dst)
There are three kinds of arguments required: boolean flags; options, text and integer; positional arguments. So far I got stuck at boolean flags and positional arguments. Unfortunately, the examples seem to be too basic even for this.
Do I really have to build separate parsers for different kinds of options (I did not manage to satisfy syntax with a single parser)?
It won't work as expected, anyway.
I can't figure out what my next step should be.