Public API
Index
ComposableCommands.AndCommandsComposableCommands.CommandComposableCommands.LongFlagComposableCommands.LongOptionComposableCommands.OrCommandsComposableCommands.RedirectedCommandComposableCommands.ShortFlagComposableCommands.ShortOptionComposableCommands.collectnodesComposableCommands.interpretComposableCommands.interpretComposableCommands.interpretComposableCommands.interpret
To utilize the public interface, first import the required packages:
julia> using ComposableCommandsFor documentation on ComposableCommands.jl, refer to this link.
Types
ComposableCommands.AndCommands — Type
AndCommands(a::AbstractCommand, b::AbstractCommand)Represent two commands executed in parallel via Julia's & composition.
ComposableCommands.Command — Type
Command(name, parameters, arguments, subcommands)Represent a command to be executed, with associated flags, options, arguments, and subcommands.
Arguments
name::String: the name of the command.parameters: an iterable of flags and options.arguments::Vector{String}: any arguments to the command.subcommands::Vector{AbstractCommand}: any subcommands to be executed in conjunction with the main command.
ComposableCommands.LongFlag — Type
LongFlag(name::String)Represent a long flag associated with a command.
ComposableCommands.LongOption — Type
LongOption(name::String, value)Represent a long option associated with a command.
ComposableCommands.OrCommands — Type
OrCommands(a::AbstractCommand, b::AbstractCommand)Represent a pipeline via Julia's pipeline(cmd1, cmd2) composition.
ComposableCommands.RedirectedCommand — Type
RedirectedCommand(source, destination)Wrap an AbstractCommand and a file (String).
It allows output redirection from a command to a file or input redirection from a file to a command. The redirection is specified by the RedirectedCommand's source and destination parameters.
Arguments
source: The source from which to redirect. Ifsourceis aString, it represents the filename of the file from which to read. Ifsourceis a subtype ofAbstractCommand, it represents the command whose output is to be redirected.destination: The destination to which to redirect. Ifdestinationis aString, it represents the filename of the file to which to write. Ifdestinationis a subtype ofAbstractCommand, it represents the command that takes the redirected output as input.
ComposableCommands.ShortFlag — Type
ShortFlag(name::String)Represent a short flag associated with a command.
ComposableCommands.ShortOption — Type
ShortOption(name::String, value)Represent a short option associated with a command.
Functions
ComposableCommands.collectnodes — Method
collectnodes(cmd::AbstractCommand) -> Vector{AbstractCommand}Return a vector containing cmd and all of its descendants in pre-order (parent before children).
ComposableCommands.interpret — Method
interpret(commands::AndCommands)Translate an AndCommands object into a Base.AndCmds that can be executed, considering the conjunction.
Examples
julia> c1 = Command("ls", [], [], []);
julia> c2 = Command("pwd", [], [], []);
julia> ac = AndCommands(c1, c2);
julia> cmd = interpret(ac)
`ls` & `pwd`
julia> typeof(cmd)
Base.AndCmdsComposableCommands.interpret — Method
interpret(command::Command)Translate a Command object into a Cmd that can be executed.
Examples
julia> c = Command("ls", [LongFlag("all")], [], []);
julia> cmd = interpret(c)
`ls --all`
julia> typeof(cmd)
CmdComposableCommands.interpret — Method
interpret(commands::OrCommands)Translate an OrCommands object into a Base.OrCmds that can be executed, considering the disjunction.
Examples
julia> c1 = Command("ls", [], [], []);
julia> c2 = Command("pwd", [], [], []);
julia> oc = OrCommands(c1, c2);
julia> cmd = interpret(oc)
pipeline(`ls`, stdout=`pwd`)
julia> typeof(cmd)
Base.OrCmdsComposableCommands.interpret — Method
interpret(command::RedirectedCommand)Translate a RedirectedCommand object into a Base.CmdRedirect that can be executed, considering the redirection.
Examples
julia> r = RedirectedCommand(Command("ls", [], [], []), "output.txt");
julia> cmd = interpret(r)
pipeline(`ls`, stdout>Base.FileRedirect("output.txt", false))
julia> typeof(cmd)
Base.CmdRedirect
julia> r = RedirectedCommand(".zshrc", Command("cat", [], [], []));
julia> cmd = interpret(r)
pipeline(`cat`, stdin<Base.FileRedirect(".zshrc", false))
julia> typeof(cmd)
Base.CmdRedirect