diff options
author | Alexander Larsson <alexander.larsson@gmail.com> | 2016-06-10 13:00:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-10 13:00:43 +0200 |
commit | 10c6e15506e3ed2037495fc7bdb268030ce45008 (patch) | |
tree | 73991775b93a5d3df94acfbef0df682d39454773 | |
parent | 874fbbff3473de9b5f2b5c29e93618cf634c7a5e (diff) | |
parent | 0d2b3ec5d0029905c4a63cccf442a0ec8ff329a8 (diff) | |
download | flatpak-10c6e15506e3ed2037495fc7bdb268030ce45008.tar.gz |
Merge pull request #32 from matthiasclasen/completion
Handle bash completion in C
-rw-r--r-- | app/flatpak-builtins-enter.c | 29 | ||||
-rw-r--r-- | app/flatpak-main.c | 9 |
2 files changed, 30 insertions, 8 deletions
diff --git a/app/flatpak-builtins-enter.c b/app/flatpak-builtins-enter.c index 3b3aa64a..89c1b1cf 100644 --- a/app/flatpak-builtins-enter.c +++ b/app/flatpak-builtins-enter.c @@ -124,7 +124,6 @@ flatpak_builtin_enter (int argc, { g_autoptr(GOptionContext) context = NULL; int rest_argv_start, rest_argc; - g_autoptr(FlatpakContext) arg_context = NULL; const char *ns_name[5] = { "user", "ipc", "net", "pid", "mnt" }; int ns_fd[G_N_ELEMENTS (ns_name)]; char pid_ns[256]; @@ -162,9 +161,6 @@ flatpak_builtin_enter (int argc, } } - arg_context = flatpak_context_new (); - g_option_context_add_group (context, flatpak_context_get_options (arg_context)); - if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; @@ -275,3 +271,28 @@ flatpak_builtin_enter (int argc, exit (status); } + +gboolean +flatpak_complete_enter (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(GError) error = NULL; + + context = g_option_context_new (""); + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + break; + + default: + break; + } + + return TRUE; +} diff --git a/app/flatpak-main.c b/app/flatpak-main.c index 0bf627c8..02b80163 100644 --- a/app/flatpak-main.c +++ b/app/flatpak-main.c @@ -60,10 +60,10 @@ static FlatpakCommand commands[] = { { "\n Running applications" }, { "run", "Run an application", flatpak_builtin_run, flatpak_complete_run }, - { "override", "Override permissions for an application", flatpak_builtin_override, flatpak_complete_override}, - { "export-file", "Grant an application access to a specific file", flatpak_builtin_export_file, flatpak_complete_export_file}, - { "make-current", "Specify default version to run", flatpak_builtin_make_current_app, flatpak_complete_make_current_app}, - { "enter", "Enter the namespace of a running application", flatpak_builtin_enter }, + { "override", "Override permissions for an application", flatpak_builtin_override, flatpak_complete_override }, + { "export-file", "Grant an application access to a specific file", flatpak_builtin_export_file, flatpak_complete_export_file }, + { "make-current", "Specify default version to run", flatpak_builtin_make_current_app, flatpak_complete_make_current_app }, + { "enter", "Enter the namespace of a running application", flatpak_builtin_enter, flatpak_complete_enter }, { "\n Manage remote repositories" }, { "remote-add", "Add a new remote repository (by URL)", flatpak_builtin_add_remote, flatpak_complete_add_remote }, @@ -87,6 +87,7 @@ static FlatpakCommand commands[] = { GOptionEntry global_entries[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL }, + { "help", '?', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, "Show help options", NULL, NULL }, { NULL } }; |