Skip to content

Commit

Permalink
Add option for config file location (closes #75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vit Guzeev committed Mar 21, 2018
1 parent 85e067b commit 569ce6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Changelogged/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data Config = Config
{ configChangelogs :: [ChangelogConfig]
, configIgnoreCommits :: Maybe [Text]
, configBranch :: Maybe Text
}
} deriving Eq

data ChangelogConfig = ChangelogConfig
{ changelogChangelog :: Turtle.FilePath
Expand All @@ -25,12 +25,12 @@ data ChangelogConfig = ChangelogConfig
, changelogVersionFiles :: Maybe [VersionFile]
-- If changelog is marked as default it's version files will be bumped with explicit level from options.
, changelogDefault :: Bool
}
} deriving Eq

data VersionFile = VersionFile
{ versionFilePath :: Turtle.FilePath
, versionFileVersionPattern :: Text
} deriving Show
} deriving (Show, Eq)

instance FromJSON Config where
parseJSON = withObject "Config" $ \o -> Config
Expand Down
9 changes: 7 additions & 2 deletions src/Changelogged/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Turtle hiding (FilePath, find)

import Control.Exception
import Data.Maybe (fromMaybe)
import Data.Text (unpack, pack)

import System.Console.ANSI (Color(..))

Expand All @@ -17,7 +18,7 @@ import Changelogged.Git
import Changelogged.Options
import Changelogged.Utils
import Changelogged.Types (Level)
import Changelogged.Pure (showText, changeloggedVersion)
import Changelogged.Pure (showText, showPath, changeloggedVersion)
import Changelogged.Config

defaultMain :: IO ()
Expand All @@ -29,9 +30,13 @@ defaultMain = do
then versionP changeloggedVersion
else do
-- load config file (or default config)
config@Config{..} <- fromMaybe defaultConfig <$> loadConfig ".changelogged.yaml"
let configPath = fromMaybe ".changelogged.yaml" (unpack . showPath <$> optConfigPath)
config@Config{..} <- fromMaybe defaultConfig <$> loadConfig configPath
-- load git info
gitInfo <- loadGitInfo optFromBC configBranch
if config == defaultConfig
then coloredPrint Blue "Using default config.\n"
else coloredPrint Blue ("Configuration file: " <> pack configPath <> "\n")
coloredPrint Blue (ppConfig config)
coloredPrint Blue (ppGitInfo gitInfo)
-- process changelogs
Expand Down
7 changes: 7 additions & 0 deletions src/Changelogged/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ parser = Options
<*> hiddenSwitch "force" "Bump versions ignoring possibly outdated changelogs."
<*> hiddenSwitch "no-check" "Do not check if changelogs have any missing entries."
<*> optional targetChangelog
<*> optional configPath
<*> hiddenSwitch "version" "Print version."
where
longSwitch name description = switch $
Expand Down Expand Up @@ -113,6 +114,10 @@ parser = Options
targetChangelog = argument readFilePath $
metavar "TARGET_CHANGELOG"
<> help ("Path to target changelog.")
configPath = option readFilePath $
long "config"
<> metavar "changelogged.yaml config file location"
<> help ("Path to config file.")

welcome :: Turtle.Description
welcome = Turtle.Description "changelogged - Changelog Manager for Git Projects"
Expand All @@ -135,6 +140,8 @@ data Options = Options
, optNoCheck :: Bool
-- | Check exactly one target changelog.
, optTargetChangelog :: Maybe Turtle.FilePath
-- | Use specified config file.
, optConfigPath :: Maybe Turtle.FilePath
-- | Print version
, optVersion :: Bool
}
Expand Down

0 comments on commit 569ce6e

Please sign in to comment.