Skip to content

Commit

Permalink
Move --cmd-log-size option behind --poll-interval
Browse files Browse the repository at this point in the history
Arguably these two are related (affect cmd-logging but not formatting).
Also improve integration tests.
  • Loading branch information
tbidne committed Feb 14, 2024
1 parent d7b636b commit a282a97
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 38 deletions.
8 changes: 4 additions & 4 deletions examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ key-hide = false
# out a CPU thread.
poll-interval = 100

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
cmd-log-size = 2048

# String that determines how the timers is formatted. Options (and examples)
# are:
#
Expand All @@ -56,10 +60,6 @@ timer-format = "prose_compact"
# key-hide = false).
cmd-name-trunc = 80

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
cmd-log-size = 2048

# Command aliases are defined here. Values can either be a single unit or a
# list of units, where a unit is either a command literal
# (e.g. bash expression) or a recursive reference to another alias.
Expand Down
8 changes: 4 additions & 4 deletions examples/config_osx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ key-hide = false
# out a CPU thread.
poll-interval = 100

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
cmd-log-size = 2048

# String that determines how the timers is formatted. Options (and examples)
# are:
#
Expand All @@ -56,10 +60,6 @@ timer-format = "prose_compact"
# key-hide = false).
cmd-name-trunc = 80

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
cmd-log-size = 2048

# Command aliases are defined here. Values can either be a single unit or a
# list of units, where a unit is either a command literal
# (e.g. bash expression) or a recursive reference to another alias.
Expand Down
8 changes: 4 additions & 4 deletions examples/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ key-hide = false
# out a CPU thread.
#poll-interval = 100

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
#cmd-log-size = 1024

# String that determines how the timers is formatted. Options (and examples)
# are:
#
Expand All @@ -55,10 +59,6 @@ key-hide = false
# 2. The command is not run with an alias (so it cannot be hidden with key-hide = false).
#cmd-name-trunc = 80

# Determines the size of the logs we read from commands (cmd-log and file-log).
# Overrides the default of 1024.
#cmd-log-size = 1024

# Command aliases are defined here. Values can either be a single unit or a
# list of units, where a unit is either a command literal
# (e.g. bash expression) or a recursive reference to another alias.
Expand Down
12 changes: 6 additions & 6 deletions src/Shrun/Configuration/Args.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ data Args = MkArgs
pollInterval :: Maybe PollInterval,
-- | Disables pollInterval.
noPollInterval :: Bool,
-- | Determines the max log size we read from commands in one go.
cmdLogSize :: Maybe (Bytes B Natural),
-- | Disables cmdLogSize.
noCmdLogSize :: Bool,
-- | How to format the timer.
timerFormat :: Maybe TimerFormat,
-- | Disables timerFormat.
Expand All @@ -129,10 +133,6 @@ data Args = MkArgs
cmdNameTrunc :: Maybe (Truncation TCmdName),
-- | Disables cmdNameTrunc.
noCmdNameTrunc :: Bool,
-- | Determines the max log size we read from commands in one go.
cmdLogSize :: Maybe (Bytes B Natural),
-- | Disables cmdLogSize.
noCmdLogSize :: Bool,
-- | Whether to log commands.
cmdLog :: Maybe Bool,
-- | Disables cmdLogging.
Expand Down Expand Up @@ -263,12 +263,12 @@ argsParser =
<*> noKeyHideParser
<*> pollIntervalParser
<*> noPollIntervalParser
<*> cmdLogSizeParser
<*> noCmdLogSizeParser
<*> timerFormatParser
<*> noTimerFormatParser
<*> cmdNameTruncParser
<*> noCmdNameTruncParser
<*> cmdLogSizeParser
<*> noCmdLogSizeParser
<*> cmdLogParser
<*> noCmdLogParser
<*> cmdLogStripControlParser
Expand Down
8 changes: 4 additions & 4 deletions src/Shrun/Configuration/Env/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ data Logging r = MkLogging
keyHide :: KeyHide,
-- | How often to poll commands for logs, in microseconds.
pollInterval :: PollInterval,
-- | The max number of command characters to display in the logs.
cmdLogSize :: Bytes B Natural,
-- | How to format the timer.
timerFormat :: TimerFormat,
-- | Truncates command names in the logs.
cmdNameTrunc :: Maybe (Truncation TCmdName),
-- | The max number of command characters to display in the logs.
cmdLogSize :: Bytes B Natural,
-- | Whether to log commands.
cmdLog :: Maybe CmdLogging,
-- | Console log queue.
Expand All @@ -181,12 +181,12 @@ instance Show (Logging r) where
. showsPrec appPrec1 (env ^. #keyHide)
. showString ", pollInterval = "
. showsPrec appPrec1 (env ^. #pollInterval)
. showString ", cmdLogSize = "
. showsPrec appPrec1 (env ^. #cmdLogSize)
. showString ", timerFormat = "
. showsPrec appPrec1 (env ^. #timerFormat)
. showString ", cmdNameTrunc = "
. showsPrec appPrec1 (env ^. #cmdNameTrunc)
. showString ", cmdLogSize = "
. showsPrec appPrec1 (env ^. #cmdLogSize)
. showString ", cmdLog = "
. showsPrec appPrec1 (env ^. #cmdLog)
. showString ", consoleLog = <TBQueue>"
Expand Down
8 changes: 4 additions & 4 deletions src/Shrun/Configuration/Toml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ data TomlConfig = MkTomlConfig
keyHide :: Maybe KeyHide,
-- | How often to poll commands for logs, in microseconds.
pollInterval :: Maybe PollInterval,
-- | Determines the max log size we read from commands in one go.
cmdLogSize :: Maybe (Bytes B Natural),
-- | How to format the timer.
timerFormat :: Maybe TimerFormat,
-- | Truncates command names in the logs.
cmdNameTrunc :: Maybe (Truncation TCmdName),
-- | Determines the max log size we read from commands in one go.
cmdLogSize :: Maybe (Bytes B Natural),
-- | Whether to log commands.
cmdLog :: Maybe CmdLoggingToml,
-- | Optional file logging. If enabled, holds the path to the file
Expand Down Expand Up @@ -129,9 +129,9 @@ instance DecodeTOML TomlConfig where
<*> decodeInit
<*> decodeCmdDisplay
<*> decodePollInterval
<*> decodeCmdLogSize
<*> decodeTimerFormat
<*> decodeCmdNameTrunc
<*> decodeCmdLogSize
<*> getFieldOptWith tomlDecoder "cmd-log"
<*> getFieldOptWith tomlDecoder "file-log"
<*> getFieldOptWith tomlDecoder "notify"
Expand Down Expand Up @@ -197,9 +197,9 @@ mergeConfig args tomlConfig =
init = combineWithDisable #init #init #noInit,
keyHide = combineWithDisable #keyHide #keyHide #noKeyHide,
pollInterval = combineWithDisable #pollInterval #pollInterval #noPollInterval,
cmdLogSize = combineWithDisable #cmdLogSize #cmdLogSize #noCmdLogSize,
timerFormat = combineWithDisable #timerFormat #timerFormat #noTimerFormat,
cmdNameTrunc = combineWithDisable #cmdNameTrunc #cmdNameTrunc #noCmdNameTrunc,
cmdLogSize = combineWithDisable #cmdLogSize #cmdLogSize #noCmdLogSize,
cmdLog,
fileLog,
notify,
Expand Down
22 changes: 13 additions & 9 deletions test/integration/Integration/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ defaultEnv = testCase "No arguments and empty config path should return default
cmdLog = False,
keyHide = KeyHideOff,
pollInterval = 10_000,
cmdLogSize = MkBytes 1024,
timerFormat = ProseCompact,
cmdNameTrunc = Nothing,
cmdLogSize = MkBytes 1024,
cmdLogStripControl = Nothing,
cmdLogLineTrunc = Nothing,
fileLog = False,
Expand All @@ -105,9 +105,9 @@ usesDefaultConfigFile = testCase "No arguments should use config from default fi
init = Just ". some file",
keyHide = KeyHideOn,
pollInterval = 127,
cmdLogSize = MkBytes 20,
timerFormat = DigitalFull,
cmdNameTrunc = Just 80,
cmdLogSize = MkBytes 1024,
cmdLog = True,
cmdLogStripControl = Just StripControlAll,
cmdLogLineTrunc = Just 150,
Expand Down Expand Up @@ -150,12 +150,12 @@ cliOverridesConfigFile testArgs = testCase "CLI args overrides config file" $ do
"--key-hide",
"--poll-interval",
"127",
"--cmd-log-size",
"512",
"--timer-format",
"digital_compact",
"--cmd-name-trunc",
"10",
"--cmd-log-size",
"512",
"--cmd-log-line-trunc",
"60",
"--cmd-log-strip-control",
Expand All @@ -176,9 +176,9 @@ cliOverridesConfigFile testArgs = testCase "CLI args overrides config file" $ do
init = Just ". another file",
keyHide = KeyHideOn,
pollInterval = 127,
cmdLogSize = MkBytes 512,
timerFormat = DigitalCompact,
cmdNameTrunc = Just 10,
cmdLogSize = MkBytes 512,
cmdLog = True,
cmdLogStripControl = Just StripControlNone,
cmdLogLineTrunc = Just 60,
Expand Down Expand Up @@ -223,9 +223,9 @@ cliOverridesConfigFileCmdLog = testCase desc $ do
init = Just "blah",
keyHide = KeyHideOff,
pollInterval = 100,
cmdLogSize = MkBytes 50,
timerFormat = DigitalFull,
cmdNameTrunc = Just 80,
cmdLogSize = MkBytes 1024,
cmdLog = True,
fileLog = True,
fileLogStripControl = Just StripControlAll,
Expand Down Expand Up @@ -255,9 +255,9 @@ ignoresDefaultConfigFile = testCase "--no-config should ignore config file" $ do
init = Nothing,
keyHide = KeyHideOff,
pollInterval = 10_000,
cmdLogSize = MkBytes 1024,
timerFormat = ProseCompact,
cmdNameTrunc = Nothing,
cmdLogSize = MkBytes 1024,
cmdLog = False,
cmdLogStripControl = Nothing,
cmdLogLineTrunc = Nothing,
Expand Down Expand Up @@ -285,6 +285,7 @@ noXOverridesToml = testCase "--no-x disables toml options" $ do
"--no-init",
"--no-key-hide",
"--no-poll-interval",
"--no-cmd-log-size",
"--no-timer-format",
"--no-cmd-name-trunc",
"--no-cmd-log",
Expand All @@ -303,9 +304,9 @@ noXOverridesToml = testCase "--no-x disables toml options" $ do
init = Nothing,
keyHide = KeyHideOff,
pollInterval = 10_000,
cmdLogSize = MkBytes 1024,
timerFormat = ProseCompact,
cmdNameTrunc = Nothing,
cmdLogSize = MkBytes 1024,
cmdLog = False,
cmdLogStripControl = Nothing,
cmdLogLineTrunc = Nothing,
Expand Down Expand Up @@ -336,6 +337,9 @@ noXOverridesArgs = testCase "--no-x disables args" $ do
"--poll-interval",
"555",
"--no-poll-interval",
"--cmd-log-size",
"512",
"--no-cmd-log-size",
"--timer-format",
"prose_full",
"--no-timer-format",
Expand Down Expand Up @@ -375,9 +379,9 @@ noXOverridesArgs = testCase "--no-x disables args" $ do
init = Nothing,
keyHide = KeyHideOff,
pollInterval = 10_000,
cmdLogSize = MkBytes 1024,
timerFormat = ProseCompact,
cmdNameTrunc = Nothing,
cmdLogSize = MkBytes 1024,
cmdLog = False,
cmdLogStripControl = Nothing,
cmdLogLineTrunc = Nothing,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Integration/Miscellaneous.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ usesRecursiveCmdExample = testCase "Uses recursive command from example" $ do
pollInterval = 127,
timerFormat = DigitalFull,
cmdNameTrunc = Just 80,
cmdLogSize = MkBytes 1024,
cmdLogSize = MkBytes 20,
cmdLog = True,
cmdLogStripControl = Just StripControlAll,
cmdLogLineTrunc = Just 150,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Integration/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ data SimpleEnv = MkSimpleEnv
init :: Maybe Text,
keyHide :: KeyHide,
pollInterval :: PollInterval,
cmdLogSize :: Bytes B Natural,
timerFormat :: TimerFormat,
cmdNameTrunc :: Maybe (Truncation TCmdName),
cmdLogSize :: Bytes B Natural,
cmdLog :: Bool,
cmdLogLineTrunc :: Maybe (Truncation TCmdLine),
cmdLogStripControl :: Maybe StripControl,
Expand All @@ -193,10 +193,10 @@ simplifyEnv = to $ \env ->
init = env ^. #init,
keyHide = env ^. (#logging % #keyHide),
pollInterval = env ^. (#logging % #pollInterval),
cmdLogSize = env ^. (#logging % #cmdLogSize),
timerFormat = env ^. (#logging % #timerFormat),
cmdLog = is (#logging % #cmdLog % _Just) env,
cmdNameTrunc = env ^. (#logging % #cmdNameTrunc),
cmdLogSize = env ^. (#logging % #cmdLogSize),
cmdLogLineTrunc = env ^? (#logging % #cmdLog %? #lineTrunc % _Just),
cmdLogStripControl = env ^? (#logging % #cmdLog %? #stripControl),
fileLog = isJust (env ^. (#logging % #fileLog)),
Expand Down
1 change: 1 addition & 0 deletions test/integration/toml/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ init = ". some file"
log-disable = true
key-hide = true
poll-interval = 127
cmd-log-size = 20
cmd-name-trunc = 80
timer-format = "digital_full"

Expand Down
1 change: 1 addition & 0 deletions test/integration/toml/osx/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ init = ". some file"
log-disable = true
key-hide = true
poll-interval = 127
cmd-log-size = 20
cmd-name-trunc = 80
timer-format = "digital_full"

Expand Down
1 change: 1 addition & 0 deletions test/integration/toml/overridden.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ timeout = "1h"
init = "blah"
log-disable = false
poll-interval = 100
cmd-log-size = 50
timer-format = "digital_full"
key-hide = false
cmd-name-trunc = 80
Expand Down
1 change: 1 addition & 0 deletions test/integration/toml/overridden_osx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ timeout = "1h"
init = "blah"
log-disable = false
poll-interval = 100
cmd-log-size = 50
timer-format = "digital_full"
key-hide = false
cmd-name-trunc = 80
Expand Down

0 comments on commit a282a97

Please sign in to comment.