-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add runConfig
#143
Add runConfig
#143
Conversation
- `runConfig` is like `run` but it allows the user to specify their own config options. One usage is like this: ```haskell main :: IO () main = do withUtf8 $ Rib.runConfig [reldir|content|] [reldir|dest|] (option (maybeReader parseAbsDir) $ long "base-url" <> help "Set the base url of the server" <> value [absdir|/|] <> showDefault <> hidden <> metavar "BASEURL" ) generateSite -- | Generate a site using a base-url generateSite :: Path Abs Dir -> Action () ```
How would this behave if I added a sub-command to |
I implemented an example use in kalhauge/rib-sample@8c70b33. The
|
Thanks. Consider this alternative approach (diff applied on your branch): diff --git a/src/Main.hs b/src/Main.hs
index 14847e3..801c00e 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -27,6 +27,7 @@ import Options.Applicative
import Path
import Rib (IsRoute, Pandoc)
import qualified Rib
+import qualified Rib.App
import qualified Rib.Parser.Pandoc as Pandoc
-- | Route corresponding to each generated static page.
@@ -59,7 +60,16 @@ instance IsRoute Route where
-- provided by Rib to do the actual generation of your static site.
main :: IO ()
main = withUtf8 $ do
- Rib.runConfig [reldir|content|] [reldir|dest|] parseConfig generateSite
+ execParser opts >>= \(config, ribCmd) ->
+ Rib.runWith [reldir|content|] [reldir|dest|] (generateSite config) ribCmd
+ where
+ opts =
+ info
+ (cliParser <**> helper)
+ (fullDesc <> progDesc "My static site generator")
+
+cliParser :: Parser (Config, Rib.App.Command)
+cliParser = (,) <$> parseConfig <*> Rib.App.commandParser
parseConfig :: Parser Config
parseConfig = do The benefit here is that it composes Rib's CLI parser ( In regards to nomenclature, this is more about being able to customize the CLI, rather than any configuration. The |
However, playing devil's advocate - it might be worth allowing custom user config in the Something like It would allow retrieval of that custom config via Shake's
|
All valid points! It would however be nice to have these common work patterns explained in the documentation. I do see that you have made a lot of changes, so I think this pull request is obsolete :) |
Yes, I've been meaning to create a 'rib guide' site similar to neuron.srid.ca. The project board for that is here: https://github.com/srid/rib/projects/2 |
runConfig
is likerun
but it allows the user to specify theirown config options. One usage is like this:
This aims to address part of the issue in #142. Only a suggestion.