Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add support for passing command-line arguments to the REPL and script environments #412

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

attie
Copy link
Member

@attie attie commented Oct 3, 2023

As discussed in #glasgow, it would be nice to make command line arguments available to the REPL and script environments (especially the latter).

This patch adds support for this, with a small example script.

Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's what the discussion asked for? They were talking about reusing the pixel format arguments, which are probably already available from iface.

Also this silently ignores excess arguments for scripts that don't parse args.

@attie
Copy link
Member Author

attie commented Oct 3, 2023

They were talking about reusing the pixel format arguments

Huh, somehow I missed that detail ... the risks of quickly reading something on mobile and thinking about it lots 🤦‍♀️
This leads me to suggest passing all arguments to these environments, and they can pluck out the remainder if desirable.

Also this silently ignores excess arguments for scripts that don't parse args.

Granted, but only after a -- terminator...

glasgow repl uart -V 3.3    -m 5 # presents Glasgow's normal error
glasgow repl uart -V 3.3 -- -m 5 # passes in [ '-m', '5' ]

@whitequark
Copy link
Member

This leads me to suggest passing all arguments to these environments, and they can pluck out the remainder if desirable.

Ew, no.

@whitequark
Copy link
Member

Granted, but only after a -- terminator...

Ah, I missed that detail. That's fine then to merge for script; I'm not sure what point this serves in repl mode?

@attie
Copy link
Member Author

attie commented Oct 3, 2023

This leads me to suggest passing all arguments to these environments, and they can pluck out the remainder if desirable.

Ew, no.

Where I've done this:

future = eval(code, {"iface":iface, "device":device, "args":args.remaining[1:]})

... I was suggesting doing this:

future = eval(code, {"iface":iface, "device":device, "args":args})

... giving the script access to Glasgow's args (e.g: pixel format from the WS2812 applet), as well as args.remaining if they want to deal with them.

Still ew?


Granted, but only after a -- terminator...

Ah, I missed that detail. That's fine then to merge for script; I'm not sure what point this serves in repl mode?

I think I agree re REPL mode as it's so heavily interactive... but perhaps changes in light of above?

@whitequark
Copy link
Member

... giving the script access to Glasgow's args (e.g: pixel format from the WS2812 applet), as well as args.remaining if they want to deal with them.

Oh, no, this is fine. (That's actually what I would suggest!)

@whitequark
Copy link
Member

but perhaps changes in light of above?

Yeah, that's clearly fine.

examples/script_args.py Outdated Show resolved Hide resolved
@attie attie force-pushed the script-args branch 2 times, most recently from 0c33fb7 to 19e3d7e Compare October 3, 2023 21:38
@attie attie enabled auto-merge October 3, 2023 21:47
@attie attie added this pull request to the merge queue Oct 3, 2023
Merged via the queue into GlasgowEmbedded:main with commit 7e3f949 Oct 3, 2023
10 of 11 checks passed
@attie attie deleted the script-args branch October 3, 2023 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants