From d9bfb7cfaef67ece9b56821371c59164f71cfb89 Mon Sep 17 00:00:00 2001 From: Martin Myrseth Date: Sun, 19 May 2024 21:59:07 +0200 Subject: [PATCH] Rename Placeholder fields => format --- src/Nixon.hs | 2 +- src/Nixon/Command/Placeholder.hs | 6 +++--- src/Nixon/Command/Run.hs | 8 ++++---- src/Nixon/Config/Markdown.hs | 8 ++++---- src/Nixon/Select.hs | 4 ++-- test/Test/Nixon/Config/Markdown.hs | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Nixon.hs b/src/Nixon.hs index de244e7..58cdf23 100644 --- a/src/Nixon.hs +++ b/src/Nixon.hs @@ -34,7 +34,7 @@ import Nixon.Language (Language (..), fromFilePath) import Nixon.Logging (log_error, log_info) import Nixon.Prelude import Nixon.Process (run) -import Nixon.Project (Project, project_path, inspectProjects) +import Nixon.Project (Project, inspectProjects, project_path) import qualified Nixon.Project as P import Nixon.Select (Candidate (..), Selection (..), SelectionType (..)) import qualified Nixon.Select as Select diff --git a/src/Nixon/Command/Placeholder.hs b/src/Nixon/Command/Placeholder.hs index 57adb6e..989c571 100644 --- a/src/Nixon/Command/Placeholder.hs +++ b/src/Nixon/Command/Placeholder.hs @@ -1,6 +1,6 @@ module Nixon.Command.Placeholder ( Placeholder (..), - PlaceholderFields (..), + PlaceholderFormat (..), PlaceholderType (..) ) where @@ -10,7 +10,7 @@ import Nixon.Prelude data PlaceholderType = Arg | EnvVar {_envName :: Text} | Stdin deriving (Eq, Show) -data PlaceholderFields +data PlaceholderFormat = -- | Interpret output as columns and extract the specified columns Columns [Int] | -- | Interpret output as fields and extract the specified fields @@ -28,7 +28,7 @@ data Placeholder = Placeholder -- | The command it's referencing name :: Text, -- | The field numbers to extract - fields :: PlaceholderFields, + format :: PlaceholderFormat, -- | If the placeholder can select multiple multiple :: Bool, -- | Pre-expanded value of the placeholder diff --git a/src/Nixon/Command/Run.hs b/src/Nixon/Command/Run.hs index 2376c0d..fe7f632 100644 --- a/src/Nixon/Command/Run.hs +++ b/src/Nixon/Command/Run.hs @@ -23,7 +23,7 @@ import Nixon.Process (run_with_output) import qualified Nixon.Process import Nixon.Project (Project) import qualified Nixon.Project as Project -import Nixon.Select (Selection (..), Selector, selector_fields, selector_multiple) +import Nixon.Select (Selection (..), Selector, selector_format, selector_multiple) import qualified Nixon.Select as Select import Nixon.Types (Nixon) import Nixon.Utils (shell_to_list, toLines) @@ -63,13 +63,13 @@ zipArgs (p : ps) (a : as) = (p, Select.search a) : zipArgs ps as resolveEnv' :: Project -> Selector Nixon -> [(P.Placeholder, Select.SelectorOpts)] -> Nixon (Maybe (Shell Text), [Text], Nixon.Process.Env) resolveEnv' project selector = foldM resolveEach (Nothing, [], []) where - resolveEach (stdin, args', envs) (P.Placeholder envType cmdName fields multiple value, select_opts) = do + resolveEach (stdin, args', envs) (P.Placeholder envType cmdName format' multiple value, select_opts) = do resolved <- case value of [] -> do cmd' <- assertCommand cmdName let select_opts' = select_opts - { selector_fields = fields, + { selector_format = format', selector_multiple = Just multiple } resolveCmd project selector cmd' select_opts' @@ -97,7 +97,7 @@ resolveCmd project selector cmd select_opts = do let projectPath = Just (Project.project_path project) linesEval <- getEvaluator (run_with_output stream) cmd args projectPath env' (toLines <$> stdin) jsonEval <- getEvaluator (run_with_output BS.stream) cmd args projectPath env' (BS.fromUTF8 <$> stdin) - selection <- selector select_opts $ case select_opts.selector_fields of + selection <- selector select_opts $ case select_opts.selector_format of P.Columns cols -> do let parseColumns' = map T.unwords . pickColumns cols . parseColumns (title, value) <- (drop 1 &&& parseColumns') . map lineToText <$> shell_to_list linesEval diff --git a/src/Nixon/Config/Markdown.hs b/src/Nixon/Config/Markdown.hs index 87b599c..7dacdcf 100644 --- a/src/Nixon/Config/Markdown.hs +++ b/src/Nixon/Config/Markdown.hs @@ -367,7 +367,7 @@ parsePlaceholderModifiers placeholder = do parsePipeFields p = (P.string "cols" *> P.many P.space *> parseFields P.Columns p) <|> (P.string "fields" *> P.many P.space *> parseFields P.Fields p) - <|> (P.string "json" $> p {P.fields = P.JSON}) + <|> (P.string "json" $> p {P.format = P.JSON}) parsePipeMultiple p = (P.string "multi" :: Parser String) $> p {P.multiple = True} @@ -378,11 +378,11 @@ parsePlaceholderModifiers placeholder = do -- Accept fields and multiple in any order (parseFields P.Fields p >>= perhaps parseMultiple) <|> (parseMultiple p >>= perhaps (parseFields P.Fields)) - parseFields :: ([Int] -> P.PlaceholderFields) -> P.Placeholder -> Parser P.Placeholder + parseFields :: ([Int] -> P.PlaceholderFormat) -> P.Placeholder -> Parser P.Placeholder parseFields fieldType p' = do fields <- mapMaybe readMaybe <$> (P.many1 P.digit `P.sepBy1` P.char ',') - when (p'.fields /= P.Lines) $ fail "Placeholder format already set" - pure $ p' {P.fields = fieldType fields} + when (p'.format /= P.Lines) $ fail "Placeholder format already set" + pure $ p' {P.format = fieldType fields} parseMultiple :: P.Placeholder -> Parser P.Placeholder parseMultiple p' = do diff --git a/src/Nixon/Select.hs b/src/Nixon/Select.hs index 4e00788..25547d5 100644 --- a/src/Nixon/Select.hs +++ b/src/Nixon/Select.hs @@ -84,7 +84,7 @@ instance Functor Selection where data SelectorOpts = SelectorOpts { selector_title :: Maybe Text, selector_search :: Maybe Text, - selector_fields :: Cmd.PlaceholderFields, + selector_format :: Cmd.PlaceholderFormat, selector_multiple :: Maybe Bool } @@ -93,7 +93,7 @@ defaults = SelectorOpts { selector_title = Nothing, selector_search = Nothing, - selector_fields = Cmd.Lines, + selector_format = Cmd.Lines, selector_multiple = Nothing } diff --git a/test/Test/Nixon/Config/Markdown.hs b/test/Test/Nixon/Config/Markdown.hs index e362dc6..2295f59 100644 --- a/test/Test/Nixon/Config/Markdown.hs +++ b/test/Test/Nixon/Config/Markdown.hs @@ -4,7 +4,7 @@ import Control.Arrow ((&&&)) import Data.Either (isLeft) import qualified Data.Text as T import qualified Nixon.Command as Cmd -import Nixon.Command.Placeholder (Placeholder (..), PlaceholderFields (..), PlaceholderType (..)) +import Nixon.Command.Placeholder (Placeholder (..), PlaceholderFormat (..), PlaceholderType (..)) import Nixon.Config.Markdown (parseCommandName, parseHeaderArgs, parseMarkdown) import Nixon.Config.Types (defaultConfig) import qualified Nixon.Config.Types as Cfg