How can a cobra command receive output of another command as arguments.
for example if my command is print [items...]
I like to redirect output of file containing items to print command.
cat items | print
I can manually read piped args using os.stdin though.
os.stdin is how I would think you would do it. Is there an alternative solution you were thinking of?
I was thinking if the redirected output line from other command can be passed in as args in func(cmd *cobra.Command, args []string) error. or Cobra can implicitly execute the Cmd per each argument piped from another command by passing the arg in args []string.
os.Stdin is what I'd expect to use; piping commands together is supposed to connect the stdout/stdin of the commands not apply them as arguments. By putting them as arguments you'd have to know how to split the output into args too and deal with unmatched quotes, spaces, etc.
xargs is the way to go, no need to fiddle around with os.Stdin or such.
cat items | xargs print
man xargs for more info ;)
Most helpful comment
xargsis the way to go, no need to fiddle around withos.Stdinor such.man xargsfor more info ;)