mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Pull the options helper out to the top level.
This commit is contained in:
parent
89e5168e65
commit
5bfedac9b6
@ -117,9 +117,11 @@ arguments = info (version <*> helper <*> ((,) <$> optionsParser <*> argumentsPar
|
|||||||
[path] -> maybe (Left $ "Cannot identify language for path: " <> path) (Right . File path . Just) (languageForFilePath path)
|
[path] -> maybe (Left $ "Cannot identify language for path: " <> path) (Right . File path . Just) (languageForFilePath path)
|
||||||
args -> Left ("cannot parse `" <> join args <> "`\nexpecting FILE:LANGUAGE or just FILE")
|
args -> Left ("cannot parse `" <> join args <> "`\nexpecting FILE:LANGUAGE or just FILE")
|
||||||
|
|
||||||
optionsReader options = eitherReader $ \ str -> maybe (Left ("expected one of: " <> intercalate ", " (fmap fst options))) (Right . snd) (find ((== str) . fst) options)
|
-- Example: --log-level error|warning|info|debug|none
|
||||||
options options fields = option (optionsReader options) (fields <> showDefaultWith (findOption options) <> metavar (intercalate "|" (fmap fst options)))
|
options :: Eq a => [(String, a)] -> Mod OptionFields a -> Parser a
|
||||||
findOption options value = maybe "" fst (find ((== value) . snd) options)
|
options options fields = option (optionsReader options) (fields <> showDefaultWith (findOption options) <> metavar (intercalate "|" (fmap fst options)))
|
||||||
|
where optionsReader options = eitherReader $ \ str -> maybe (Left ("expected one of: " <> intercalate ", " (fmap fst options))) (Right . snd) (find ((== str) . fst) options)
|
||||||
|
findOption options value = maybe "" fst (find ((== value) . snd) options)
|
||||||
|
|
||||||
|
|
||||||
-- Example: semantic parse --symbols --fields=symbol,path,language,kind,line,span
|
-- Example: semantic parse --symbols --fields=symbol,path,language,kind,line,span
|
||||||
|
Loading…
Reference in New Issue
Block a user