mirror of
https://github.com/NorfairKing/feedback.git
synced 2024-11-27 00:47:13 +03:00
Configurable gitignore filter
This commit is contained in:
parent
7a5ad699bd
commit
6ee86853f8
@ -44,7 +44,7 @@ See `feedback-test --help` for more details.
|
||||
|----|-|-|-|-|
|
||||
| Indication of command starting | ✔️ | ✔️ | C | C |
|
||||
| Indication of time | ✔️ | C | C | C |
|
||||
| Clear screen between feedback | ✔️ | C | C | ✔️ |
|
||||
| Clear screen between feedback | ✔️ | C | C | C |
|
||||
| Gitignore-aware | ✔️ | ✖️ | ✔️ | ✖ |
|
||||
| Named feedback loops | ✔️ | ✖️ | ✖ | ✖ |
|
||||
| Configurable feedback loops | ✔️ | ✔️ | ✖ | ✖ |
|
||||
|
@ -27,11 +27,30 @@ import Path.IO
|
||||
import Paths_feedback
|
||||
|
||||
data LoopSettings = LoopSettings
|
||||
{ loopSettingRunSettings :: !RunSettings,
|
||||
{ loopSettingFilterSettings :: !FilterSettings,
|
||||
loopSettingRunSettings :: !RunSettings,
|
||||
loopSettingOutputSettings :: !OutputSettings
|
||||
}
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
combineToLoopSettings :: Flags -> Environment -> Maybe OutputConfiguration -> LoopConfiguration -> IO LoopSettings
|
||||
combineToLoopSettings Flags {..} Environment {} mDefaultOutputConfig LoopConfiguration {..} = do
|
||||
let filterSettingGitingore = fromMaybe True loopConfigGitignore
|
||||
let loopSettingFilterSettings = FilterSettings {..}
|
||||
let runSettingCommand = loopConfigCommand
|
||||
let runSettingExtraEnv = loopConfigExtraEnv
|
||||
runSettingWorkingDir <- mapM resolveDir' loopConfigWorkingDir
|
||||
|
||||
let loopSettingRunSettings = RunSettings {..}
|
||||
let outputConfig = liftA2 (<>) loopConfigOutputConfiguration mDefaultOutputConfig
|
||||
let loopSettingOutputSettings = combineToOutputSettings flagOutputFlags outputConfig
|
||||
pure LoopSettings {..}
|
||||
|
||||
data FilterSettings = FilterSettings
|
||||
{ filterSettingGitingore :: !Bool
|
||||
}
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
data RunSettings = RunSettings
|
||||
{ runSettingCommand :: !Command,
|
||||
runSettingExtraEnv :: !(Map String String),
|
||||
@ -39,17 +58,6 @@ data RunSettings = RunSettings
|
||||
}
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
combineToLoopSettings :: Flags -> Environment -> Maybe OutputConfiguration -> LoopConfiguration -> IO LoopSettings
|
||||
combineToLoopSettings Flags {..} Environment {} mDefaultOutputConfig LoopConfiguration {..} = do
|
||||
let runSettingCommand = loopConfigCommand
|
||||
let runSettingExtraEnv = loopConfigExtraEnv
|
||||
runSettingWorkingDir <- mapM resolveDir' loopConfigWorkingDir
|
||||
|
||||
let loopSettingRunSettings = RunSettings {..}
|
||||
let outputConfig = liftA2 (<>) loopConfigOutputConfiguration mDefaultOutputConfig
|
||||
let loopSettingOutputSettings = combineToOutputSettings flagOutputFlags outputConfig
|
||||
pure LoopSettings {..}
|
||||
|
||||
data OutputSettings = OutputSettings
|
||||
{ outputSettingClear :: !Clear
|
||||
}
|
||||
@ -76,6 +84,7 @@ instance HasCodec Configuration where
|
||||
|
||||
data LoopConfiguration = LoopConfiguration
|
||||
{ loopConfigCommand :: !Command,
|
||||
loopConfigGitignore :: !(Maybe Bool),
|
||||
loopConfigExtraEnv :: !(Map String String),
|
||||
loopConfigWorkingDir :: !(Maybe FilePath),
|
||||
loopConfigOutputConfiguration :: !(Maybe OutputConfiguration)
|
||||
@ -91,6 +100,7 @@ instance HasCodec LoopConfiguration where
|
||||
object "LoopConfiguration" $
|
||||
LoopConfiguration
|
||||
<$> commandObjectCodec .= loopConfigCommand
|
||||
<*> optionalField "gitignore" "whether to ignore files that are not in the git repo" .= loopConfigGitignore
|
||||
<*> optionalFieldWithOmittedDefault "env" M.empty "extra environment variables to set" .= loopConfigExtraEnv
|
||||
<*> optionalField "working-dir" "where the process will be run" .= loopConfigWorkingDir
|
||||
<*> optionalField "output" "output configuration for this loop" .= loopConfigOutputConfiguration
|
||||
@ -108,6 +118,7 @@ makeLoopConfiguration :: Command -> LoopConfiguration
|
||||
makeLoopConfiguration c =
|
||||
LoopConfiguration
|
||||
{ loopConfigCommand = c,
|
||||
loopConfigGitignore = Nothing,
|
||||
loopConfigExtraEnv = M.empty,
|
||||
loopConfigWorkingDir = Nothing,
|
||||
loopConfigOutputConfiguration = Nothing
|
||||
|
@ -41,7 +41,7 @@ runFeedbackLoop =
|
||||
-- 0.1 second debouncing, 0.001 was too little
|
||||
let conf = FS.defaultConfig {confDebounce = Debounce 0.1}
|
||||
FS.withManagerConf conf $ \watchManager -> do
|
||||
eventFilter <- mkEventFilter here
|
||||
eventFilter <- mkEventFilter here loopSettingFilterSettings
|
||||
stopListeningAction <-
|
||||
FS.watchTree
|
||||
watchManager
|
||||
@ -54,9 +54,9 @@ runFeedbackLoop =
|
||||
(outputWorker loopSettingOutputSettings outputChan)
|
||||
stopListeningAction
|
||||
|
||||
mkEventFilter :: Path Abs Dir -> IO (FS.Event -> Bool)
|
||||
mkEventFilter here = do
|
||||
mGitFiles <- gitLsFiles here
|
||||
mkEventFilter :: Path Abs Dir -> FilterSettings -> IO (FS.Event -> Bool)
|
||||
mkEventFilter here FilterSettings {..} = do
|
||||
mGitFiles <- if filterSettingGitingore then gitLsFiles here else pure Nothing
|
||||
pure $ \event ->
|
||||
standardEventFilter here event
|
||||
&& maybe True (eventPath event `S.member`) mGitFiles
|
||||
|
Loading…
Reference in New Issue
Block a user