Skip to content

Commit

Permalink
Add basic command line options parser
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
seqre committed Apr 27, 2021
1 parent fa2be37 commit 0217e5f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Sudoku/Parser.hs
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

0 comments on commit 0217e5f

Please sign in to comment.