bonzai icon indicating copy to clipboard operation
bonzai copied to clipboard

Add "into" (`--`) operator

Open rwxrob opened this issue 2 years ago • 0 comments

The -- "into" operator (end of options in other shells) is the equivalent of a pipe in BonzaiShell. It signifies that one command has ended and that any output to os.Stdout should be redirected into a buffer and set as the last argument to the command immediately following the "into" operator. This is the exact behavior of text/template when adding FuncMap functions that take piped input and should feel normal to any Go programmer who has worked with templates.

We cannot use the actual pipe operator (|) because it would have to be quoted or escaped constantly (like find command requires). By using -- the hosting shell (if there is one) will ignore it. And since we are doing our own argument parsing (and not using getopt) use of -- is fine. In fact, because -- does have special meaning to getopt we can purposefully ensure that no Bonzai command ever adds getopt (since technically it could be added now). This conflict, therefore, has a purpose.

rwxrob avatar Apr 14 '22 07:04 rwxrob