So we have an app that we’ve registered with the tk-shell engine so we can invoke it from the command line. I’m trying to figure out the best way to expose optional arguments to this command so we can call it like so:
./tank <optional_context> my_app -optionalflag1 foo -optionalflag2 bar
right now it appears that every token after ‘my_app’ gets passed as an argument to the callback function registered via sgtk.platform.Engine.register_command(), which means it’s beholden to the number of arguments that the callback function accepts. I’ve considered encapsulating all optional arguments in quotes like so:
But this feels inelegant. I’d imagine there’s a very simple way to accomplish specifying additional arguments but for the life of me I don’t see it documented.
So, you could fork/hack tk-shell to do what you want, or you can write a wrapper that has a nice command line UX, but then parses/repacks its inputs to send on to tank in a way that the callback accepts.
In the meantime, we’ll run it by @rob as well – seems like a totally reasonable feature request.
Thanks for the feedback @tannaz and @Jeff_Beeland . The wrapper was my first inclination as well, but I decided to deep-dive into tk-multi-launchapp to see if there was another way of doing it (since presumably all the DCC’s being launched also take a variable number of arguments). Turns out the way they resolve this is to construct the callback function to use the *args variable length argument list:
def my_callback(*args, **kwargs)
It seems this happily allows me to pass any arbitrary tokens after my invocation and they all get passed on to my callback function.