-
-
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
Custom subcommands #80
Comments
BTW this is something I want for myself too. Not sure what prompted you to make this issue but 👍 |
I wanted to write a subcommand to be able to modify source files. Specifically to add a new entry to a .toml file (see below), but I imagine someone may want to use for other purposes, like create a new blog post draft with date and other template stuff automatically filled in. Currently I hack around it like this: main :: IO ()
main = do
-- HACK: Until https://github.com/srid/rib/issues/80
getArgs >>= \case
["tidbit", url] -> do
-- TODO: Get og:title, og:image, etc..?
today <- utctDay <$> getCurrentTime
let tidbit = Tidbit today "TITLE" (toText url) [] Nothing
modifyFile "a/tidbits.toml" $ \content ->
toString $
intercalate @Char
"\n"
[ "[[tidbit]]",
toString $ Tidbit.toToml tidbit,
content
]
_ -> main'
where
modifyFile path f = do
let tmpPath = path <> ".tmp"
content <- f <$> readFile path
writeFile tmpPath content
copyFile tmpPath path
removeFile tmpPath
main' :: IO ()
main' = Rib.run [reldir|a|] [reldir|b|] $ do
Rib.buildStaticFiles [[relfile|static/**|]]
[...] |
Turns out that this 'feature', as originally thought out, is unnecessarily complex as well. All that rib needs to do is expose its own command line |
Allow users to add custom subcommands to the built executable.
The text was updated successfully, but these errors were encountered: