Yes, using the Automation Framework.
I'm begining to sound like a broken rocord arent I :)
Create and test your context and script in the Desktop.
Create an Automation plan in the desktop using that context.
Run and test it in the desktop.
Assuming it all works export the plan as a yaml file.
You can now run that yaml AF plan from the command line.
Cheers,
Simon