diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-27 20:44:28 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-27 20:44:28 +0200 |
commit | bdd1d73969ff9015f444239099ed4cdd6afff910 (patch) | |
tree | d3a7332cdde0e549dca9da48d1576f761da448bb /src/Command | |
parent | a56d5c3c753241d205ed2f3e28618d18bf8eb1d9 (diff) |
Test repo subtree
Diffstat (limited to 'src/Command')
-rw-r--r-- | src/Command/Subtree.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Command/Subtree.hs b/src/Command/Subtree.hs new file mode 100644 index 0000000..8d42d73 --- /dev/null +++ b/src/Command/Subtree.hs @@ -0,0 +1,46 @@ +module Command.Subtree ( + SubtreeCommand, +) where + +import Data.Text (Text) +import Data.Text qualified as T + +import Command +import Output +import Repo + + +data SubtreeCommand = SubtreeCommand SubtreeOptions [ Text ] + +data SubtreeOptions = SubtreeOptions + +instance Command SubtreeCommand where + commandName _ = "subtree" + commandDescription _ = "Resolve subdirectory of given repo tree" + + type CommandArguments SubtreeCommand = [ Text ] + + commandUsage _ = T.pack $ unlines $ + [ "Usage: minici subtree <tree> <path>" + ] + + type CommandOptions SubtreeCommand = SubtreeOptions + defaultCommandOptions _ = SubtreeOptions + + commandInit _ opts = SubtreeCommand opts + commandExec = cmdSubtree + + +cmdSubtree :: SubtreeCommand -> CommandExec () +cmdSubtree (SubtreeCommand SubtreeOptions args) = do + [ treeParam, path ] <- return args + out <- getOutput + repo <- getDefaultRepo + + let ( tree, subdir ) = + case T.splitOn "(" treeParam of + (t : param : _) -> ( t, T.unpack $ T.takeWhile (/= ')') param ) + _ -> ( treeParam, "" ) + + subtree <- getSubtree Nothing (T.unpack path) =<< readTree repo subdir tree + outputMessage out $ textTreeId $ treeId subtree |