-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an option for changing the base url
- Loading branch information
Showing
6 changed files
with
84 additions
and
66 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
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
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
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
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 |
---|---|---|
@@ -1,45 +1,82 @@ | ||
{-# LANGUAGE BlockArguments, ScopedTypeVariables, TupleSections #-} | ||
{-# LANGUAGE DeriveGeneric, TypeFamilies #-} | ||
{-# LANGUAGE DeriveGeneric, TypeFamilies, DerivingStrategies #-} | ||
|
||
-- | Global build options. | ||
module Shake.Options | ||
( Option(..) | ||
( Options(..), _1LabOptDescrs | ||
, defaultOptions | ||
, setOptions | ||
|
||
, getSkipTypes | ||
, getSkipAgda | ||
, getWatching | ||
, getBaseUrl | ||
) where | ||
|
||
import Development.Shake.Classes | ||
import Development.Shake | ||
|
||
import Data.Maybe | ||
|
||
import GHC.Generics (Generic) | ||
|
||
data Option | ||
= SkipTypes -- ^ Skip generating types when emitting HTML. | ||
| SkipAgda -- ^ Skip typechecking Agda, emitting the markdown directly. | ||
| Watching -- ^ Launch in watch mode. Prevents some build tasks running. | ||
import System.Console.GetOpt | ||
|
||
data Options = Options | ||
{ _optSkipTypes :: !Bool | ||
-- ^ Skip generating types when emitting HTML. | ||
, _optSkipAgda :: !Bool | ||
-- ^ Skip typechecking Agda, emitting the markdown directly. | ||
, _optWatching :: Maybe (Maybe String) | ||
-- ^ Launch in watch mode. Prevents some build tasks running. | ||
, _optBaseUrl :: String | ||
-- ^ Base URL for absolute paths | ||
} | ||
deriving (Eq, Show, Typeable, Generic) | ||
|
||
instance Hashable Option where | ||
instance Binary Option where | ||
instance NFData Option where | ||
instance Hashable Options | ||
instance Binary Options | ||
instance NFData Options | ||
|
||
defaultOptions :: Options | ||
defaultOptions = Options | ||
{ _optSkipTypes = False | ||
, _optSkipAgda = False | ||
, _optWatching = Nothing | ||
, _optBaseUrl = "https://1lab.dev" | ||
} | ||
|
||
type instance RuleResult Option = Bool | ||
data GetOptions = GetOptions deriving (Eq, Show, Typeable, Generic) | ||
|
||
instance Hashable GetOptions | ||
instance Binary GetOptions | ||
instance NFData GetOptions | ||
|
||
type instance RuleResult GetOptions = Options | ||
|
||
-- | Set which option flags are enabled. | ||
setOptions :: [Option] -> Rules () | ||
setOptions :: Options -> Rules () | ||
setOptions options = do | ||
_ <- addOracle (pure . getOption) | ||
_ <- addOracle $ \GetOptions -> pure options | ||
pure () | ||
where | ||
getOption SkipTypes = SkipTypes `elem` options | ||
|| SkipAgda `elem` options | ||
|| Watching `elem` options | ||
getOption SkipAgda = SkipAgda `elem` options | ||
getOption Watching = Watching `elem` options | ||
|
||
getSkipTypes, getSkipAgda, getWatching :: Action Bool | ||
getSkipTypes = askOracle SkipTypes | ||
getSkipAgda = askOracle SkipAgda | ||
getWatching = askOracle Watching | ||
getSkipTypes = _optSkipTypes <$> askOracle GetOptions | ||
getSkipAgda = _optSkipAgda <$> askOracle GetOptions | ||
getWatching = isJust . _optWatching <$> askOracle GetOptions | ||
|
||
getBaseUrl :: Action String | ||
getBaseUrl = _optBaseUrl <$> askOracle GetOptions | ||
|
||
_1LabOptDescrs :: [OptDescr (Options -> Options)] | ||
_1LabOptDescrs = | ||
[ Option "w" ["watch"] (OptArg (\s r -> r { _optWatching = Just s, _optSkipTypes = True }) "COMMAND") | ||
"Start 1lab-shake in watch mode. Starts a persistent process which runs a subset of build tasks for \ | ||
\interactive editing. Implies --skip-types.\nOptionally takes a command to run after the build has finished." | ||
, Option [] ["skip-types"] (NoArg (\r -> r { _optSkipTypes = True })) | ||
"Skip generating type tooltips when compiling Agda to HTML." | ||
, Option [] ["skip-agda"] (NoArg (\r -> r { _optSkipAgda = True, _optSkipTypes = True })) | ||
"Skip typechecking Agda. Markdown files are read from src/ directly." | ||
, Option "b" ["base-url"] (ReqArg (\s r -> r { _optBaseUrl = s }) "URL") | ||
"The base URL to use for absolute links. Should include the protocol." | ||
] |
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