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

Add CLI argument parsing example #1626

Open
REALERvolker1 opened this issue Feb 26, 2024 · 0 comments
Open

Add CLI argument parsing example #1626

REALERvolker1 opened this issue Feb 26, 2024 · 0 comments
Labels
enhancement New feature or request examples

Comments

@REALERvolker1
Copy link

REALERvolker1 commented Feb 26, 2024

Hey there. I am making a GTK application, and I would like to take command line arguments.

I can run a GTK application that ignores command line arguments that are passed, my code for this is

let app = gtk4::Application::builder()
    .application_id("com.github.REALERvolker1.example")
    .build();
app.run_with_args::<glib::GString>(&[]);

However, I would like to learn how to use GTK's built-in argument parsing, hopefully removing some dependencies. I know that it is definitely harder than clap or rolling my own custom one (requiring me to either hardcode or macro a bunch of stuff into oblivion), but I would like to try it.

I checked out the GTK documentation, and it seems like handle-local-options is the best way to do this. It won't give me as much control, but I would prefer to have the help page formatting from gtk, even if it does include the --help-all and --help-gapplication flags. I don't know if this is how that works, please do correct me if I'm wrong. I would like to use the nice layout that comes with this, and keep everything nice and structured. The help text requirement is also really nice imo.

I found that I have to add a bunch of gio::ActionEntry to the application. However, I don't know how that translates into CLI argument parsing, and how that interacts with the app.connect_command_line(|app, cli| {/* ... */}); handler.

I have seen the methods on the ApplicationCommandLine class, and it looks very featureful. Having an arg parsing example would really make this a lot easier to learn.

There is definitely interest in this see (#730), and it would also clear up some confusion with gtk weirdness (#1436, #1039)

@REALERvolker1 REALERvolker1 added the enhancement New feature or request label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request examples
Projects
None yet
Development

No branches or pull requests

2 participants