diff --git a/README.md b/README.md index 88ef557..c107252 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ Type `--help` for some more information. ```shell dconf2nix - Nixify dconf configuration files -Usage: dconf2nix [-v|--version] - [[-r|--root ARG] [--verbose] | (-i|--input ARG) - (-o|--output ARG) [-r|--root ARG] [--verbose]] +Usage: dconf2nix [-v|--version] [-r|--root ARG] [--verbose] + [(-i|--input ARG) (-o|--output ARG)] + Convert a dconf file into a Nix file, as expected by Home Manager. Available options: @@ -117,8 +117,6 @@ Available options: --verbose Verbose mode (debug) -i,--input ARG Path to the dconf file (input) -o,--output ARG Path to the Nix output file (to be created) - -r,--root ARG Custom root path. e.g.: system/locale/ - --verbose Verbose mode (debug) ``` #### Custom root diff --git a/app/Main.hs b/app/Main.hs index 2adf0c2..8d54205 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,9 +2,9 @@ module Main where -import CommandLine ( FileArgs(..) +import CommandLine ( Args(..) + , FileArgs(..) , Input(..) - , StdinArgs(..) , runArgs ) import DConf2Nix ( dconf2nixFile @@ -13,7 +13,7 @@ import DConf2Nix ( dconf2nixFile main :: IO () main = runArgs >>= \case - FileInput (FileArgs i o r v) -> + Args r v (FileInput (FileArgs i o)) -> dconf2nixFile i o r v - StdinInput (StdinArgs r v) -> + Args r v StdinInput -> dconf2nixStdin r v diff --git a/src/CommandLine.hs b/src/CommandLine.hs index 5cef751..02a499f 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -1,7 +1,7 @@ module CommandLine - ( FileArgs(..) + ( Args(..) + , FileArgs(..) , Input(..) - , StdinArgs(..) , runArgs ) where @@ -12,18 +12,17 @@ import DConf.Data import Options.Applicative import Paths_dconf2nix ( version ) -data Input = FileInput FileArgs | StdinInput StdinArgs +data Args = Args + { argsRoot :: Root + , argsVerbosity :: Verbosity + , argsInput :: Input + } + +data Input = FileInput FileArgs | StdinInput data FileArgs = FileArgs { fileInput :: InputFilePath , fileOutput :: OutputFilePath - , fileRoot :: Root - , fileVerbosity :: Verbosity - } - -data StdinArgs = StdinArgs - { stdinRoot :: Root - , stdinVerbosity :: Verbosity } verbosityArgs :: Parser Verbosity @@ -46,12 +45,9 @@ fileArgs = fmap FileInput $ FileArgs "Path to the Nix output file (to be created)" ) ) - <*> rootArgs - <*> verbosityArgs stdinArgs :: Parser Input -stdinArgs = - StdinInput <$> (StdinArgs <$> rootArgs <*> verbosityArgs) +stdinArgs = pure StdinInput versionInfo :: String versionInfo = unlines @@ -72,11 +68,13 @@ versionOpt :: Parser (a -> a) versionOpt = infoOption versionInfo (long "version" <> short 'v' <> help "Show the current version") -runArgs :: IO Input +runArgs :: IO Args runArgs = let + args = Args <$> rootArgs <*> verbosityArgs <*> (stdinArgs <|> fileArgs) + opts = info - (helper <*> versionOpt <*> (stdinArgs <|> fileArgs)) + (helper <*> versionOpt <*> args) ( fullDesc <> progDesc "Convert a dconf file into a Nix file, as expected by Home Manager."