-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic command line options parser
Closes #6
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Sudoku.Parser | ||
( greeter | ||
) where | ||
|
||
import Options.Applicative | ||
import Data.Semigroup ((<>)) | ||
|
||
import Sudoku.Sudoku (dispatch) | ||
|
||
data Options = Options { | ||
algorithm :: String, | ||
file :: String | ||
} deriving (Show) | ||
|
||
|
||
options :: Parser Options | ||
options = Options | ||
<$> strOption | ||
( long "algorithm" | ||
<> short 'a' | ||
<> metavar "ALGO" | ||
<> value "auto" | ||
<> showDefault | ||
<> completer (listCompleter solvers) | ||
<> help "Algorithm to be used" ) | ||
<*> strOption | ||
( long "file" | ||
<> short 'f' | ||
<> metavar "FILE" | ||
<> value "" | ||
<> help "File path with sudokus to solve" ) | ||
|
||
|
||
greeter :: ParserInfo Options | ||
greeter = info (options <**> helper) | ||
( fullDesc | ||
<> footer solversDoc | ||
<> header "sudoku-solver - solver for sudoku with different algorithms" ) | ||
|
||
-- TODO: Change to DOC | ||
solversDoc :: String | ||
solversDoc = "Available solvers:" ++ (("\t" ++) =<< solvers) | ||
|
||
solvers :: [String] | ||
solvers = map fst dispatch |