Permalink
Browse files

Pump some steroids on the autocompletion feature

  • Loading branch information...
ydahhrk committed Dec 10, 2018
1 parent 27a7e50 commit 0557f39a5c7c1666f9a2843612d5cc5a46cef0e2
@@ -13,6 +13,7 @@ static struct global_type gt_bool = {
.size = sizeof(config_bool),
.print = print_bool,
.parse = parse_bool,
.candidates = "true false",
};

static struct global_type gt_uint8 = {
@@ -76,6 +77,7 @@ static struct global_type gt_hairpin_mode = {
.print = print_hairpin_mode,
.parse = parse_hairpin_mode,
.validate = validate_hairpin_mode,
.candidates = "off simple intrinsic",
};

/* TODO (fine) turn this into a constant. */
@@ -93,6 +95,7 @@ static struct global_field global_fields[] = {
.offset = offsetof(struct globals, pool6),
.xt = XT_BOTH,
.validate = validate_pool6,
.candidates = WELL_KNOWN_PREFIX,
}, {
.name = "zeroize-traffic-class",
.type = &gt_bool,
@@ -35,6 +35,7 @@ struct global_type {
print_function print;
parse_function parse;
validate_function validate;
char *candidates; /* Same as in struct wargp_type. */
};

struct global_field {
@@ -47,6 +48,7 @@ struct global_field {
__u64 max;
print_function print; /* Overrides type->print. */
validate_function validate; /* Overrides type->validate. */
char *candidates; /* Overrides type->candidates. */
};

void get_global_fields(struct global_field **fields, unsigned int *len);
@@ -95,6 +95,8 @@

/* -- IPv6 Pool -- */

#define WELL_KNOWN_PREFIX "64:ff9b::/96"

/**
* RFC 6052's allowed prefix lengths.
*/
@@ -76,9 +76,9 @@ int handle_bib_display(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_bib_display_opts(char *prefix)
void autocomplete_bib_display(void *args)
{
print_wargp_opts(display_opts, prefix);
print_wargp_opts(display_opts);
}

struct taddr_tuple {
@@ -157,9 +157,9 @@ int handle_bib_add(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_bib_add_opts(char *prefix)
void autocomplete_bib_add(void *args)
{
print_wargp_opts(add_opts, prefix);
print_wargp_opts(add_opts);
}

struct rm_args {
@@ -212,7 +212,7 @@ int handle_bib_remove(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_bib_remove_opts(char *prefix)
void autocomplete_bib_remove(void *args)
{
print_wargp_opts(remove_opts, prefix);
print_wargp_opts(remove_opts);
}
@@ -5,8 +5,8 @@ int handle_bib_display(char *iname, int argc, char **argv, void *arg);
int handle_bib_add(char *iname, int argc, char **argv, void *arg);
int handle_bib_remove(char *iname, int argc, char **argv, void *arg);

void print_bib_display_opts(char *prefix);
void print_bib_add_opts(char *prefix);
void print_bib_remove_opts(char *prefix);
void autocomplete_bib_display(void *args);
void autocomplete_bib_add(void *args);
void autocomplete_bib_remove(void *args);

#endif /* SRC_USERSPACE_CLIENT_ARGP_BIB_H_ */
@@ -72,9 +72,9 @@ int handle_blacklist4_display(char *iname, int argc, char **argv, void *arg)
return 0;
}

void print_blacklist4_display_opts(char *prefix)
void autocomplete_blacklist4_display(void *args)
{
print_wargp_opts(display_opts, prefix);
print_wargp_opts(display_opts);
}

struct add_args {
@@ -121,9 +121,9 @@ int handle_blacklist4_add(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_blacklist4_add_opts(char *prefix)
void autocomplete_blacklist4_add(void *args)
{
print_wargp_opts(add_opts, prefix);
print_wargp_opts(add_opts);
}

struct rm_args {
@@ -168,9 +168,9 @@ int handle_blacklist4_remove(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_blacklist4_remove_opts(char *prefix)
void autocomplete_blacklist4_remove(void *args)
{
print_wargp_opts(remove_opts, prefix);
print_wargp_opts(remove_opts);
}

int handle_blacklist4_flush(char *iname, int argc, char **argv, void *arg)
@@ -191,7 +191,7 @@ int handle_blacklist4_flush(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_blacklist4_flush_opts(char *prefix)
void autocomplete_blacklist4_flush(void *args)
{
/* Nothing needed here. */
}
@@ -6,9 +6,9 @@ int handle_blacklist4_add(char *iname, int argc, char **argv, void *arg);
int handle_blacklist4_remove(char *iname, int argc, char **argv, void *arg);
int handle_blacklist4_flush(char *iname, int argc, char **argv, void *arg);

void print_blacklist4_display_opts(char *prefix);
void print_blacklist4_add_opts(char *prefix);
void print_blacklist4_remove_opts(char *prefix);
void print_blacklist4_flush_opts(char *prefix);
void autocomplete_blacklist4_display(void *args);
void autocomplete_blacklist4_add(void *args);
void autocomplete_blacklist4_remove(void *args);
void autocomplete_blacklist4_flush(void *args);

#endif /* SRC_USERSPACE_CLIENT_ARGP_BLACKLIST_H_ */
@@ -84,9 +84,9 @@ int handle_eamt_display(char *iname, int argc, char **argv, void *arg)
return 0;
}

void print_eamt_display_opts(char *prefix)
void autocomplete_eamt_display(void *args)
{
print_wargp_opts(display_opts, prefix);
print_wargp_opts(display_opts);
}

struct wargp_eamt_entry {
@@ -164,9 +164,9 @@ int handle_eamt_add(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_eamt_add_opts(char *prefix)
void autocomplete_eamt_add(void *args)
{
print_wargp_opts(add_opts, prefix);
print_wargp_opts(add_opts);
}

struct rm_args {
@@ -213,9 +213,9 @@ int handle_eamt_remove(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_eamt_remove_opts(char *prefix)
void autocomplete_eamt_remove(void *args)
{
print_wargp_opts(remove_opts, prefix);
print_wargp_opts(remove_opts);
}

int handle_eamt_flush(char *iname, int argc, char **argv, void *arg)
@@ -240,7 +240,7 @@ int handle_eamt_flush(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_eamt_flush_opts(char *prefix)
void autocomplete_eamt_flush(void *args)
{
/* Nothing needed here. */
}
@@ -6,9 +6,9 @@ int handle_eamt_add(char *iname, int argc, char **argv, void *arg);
int handle_eamt_remove(char *iname, int argc, char **argv, void *arg);
int handle_eamt_flush(char *iname, int argc, char **argv, void *arg);

void print_eamt_display_opts(char *prefix);
void print_eamt_add_opts(char *prefix);
void print_eamt_remove_opts(char *prefix);
void print_eamt_flush_opts(char *prefix);
void autocomplete_eamt_display(void *args);
void autocomplete_eamt_add(void *args);
void autocomplete_eamt_remove(void *args);
void autocomplete_eamt_flush(void *args);

#endif /* SRC_USERSPACE_CLIENT_ARGP_EAMT_H_ */
@@ -51,7 +51,7 @@ int handle_file_update(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_file_update_opts(char *prefix)
void autocomplete_file_update(void *args)
{
print_wargp_opts(update_opts, prefix);
/* Do nothing; default to autocomplete directory path */
}
@@ -2,6 +2,6 @@
#define SRC_USERSPACE_CLIENT_ARGP_FILE_H_

int handle_file_update(char *iname, int argc, char **argv, void *arg);
void print_file_update_opts(char *prefix);
void autocomplete_file_update(void *args);

#endif /* SRC_USERSPACE_CLIENT_ARGP_FILE_H_ */
@@ -71,9 +71,9 @@ int handle_global_display(char *iname, int argc, char **argv, void *arg)
return error ? : handle_display_response(&dargs, &config);
}

void print_global_display_opts(char *prefix)
void autocomplete_global_display(void *args)
{
print_wargp_opts(display_opts, prefix);
print_wargp_opts(display_opts);
}

struct update_args {
@@ -129,9 +129,16 @@ static int handle_global_update(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_global_update_opts(char *prefix)
void autocomplete_global_update(void *arg)
{
print_wargp_opts(update_opts, prefix);
struct global_field *field = arg;

if (field->candidates)
printf("%s ", field->candidates);
else if (field->type->candidates)
printf("%s ", field->type->candidates);

print_wargp_opts(update_opts);
}

struct cmd_option *build_global_update_children(void)
@@ -151,8 +158,8 @@ struct cmd_option *build_global_update_children(void)
opts[i].label = global_fields[i].name;
opts[i].xt = global_fields[i].xt;
opts[i].handler = handle_global_update;
opts[i].handle_autocomplete = autocomplete_global_update;
opts[i].args = &global_fields[i];
opts[i].print_opts = print_global_update_opts;
}

return opts;
@@ -2,7 +2,7 @@
#define SRC_USERSPACE_CLIENT_ARGP_GLOBAL_H_

int handle_global_display(char *iname, int argc, char **argv, void *arg);
void print_global_display_opts(char *prefix);
void autocomplete_global_display(void *args);

struct cmd_option *build_global_update_children(void);

@@ -3,6 +3,7 @@
#include <string.h>
#include <net/if.h>

#include "common/constants.h"
#include "common/config.h"
#include "usr/common/netlink.h"
#include "usr/common/requirements.h"
@@ -45,6 +46,7 @@ static int parse_iname(void *void_field, int key, char *str)
struct wargp_type wt_iname = {
.argument = "<instance name>",
.parse = parse_iname,
.candidates = "default",
};

struct display_args {
@@ -144,9 +146,9 @@ int handle_instance_display(char *iname, int argc, char **argv, void *arg)
return 0;
}

void print_instance_display_opts(char *prefix)
void autocomplete_instance_display(void *args)
{
print_wargp_opts(display_opts, prefix);
print_wargp_opts(display_opts);
}

struct add_args {
@@ -220,9 +222,9 @@ int handle_instance_add(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_instance_add_opts(char *prefix)
void autocomplete_instance_add(void *args)
{
print_wargp_opts(add_opts, prefix);
print_wargp_opts(add_opts);
}

struct rm_args {
@@ -260,9 +262,9 @@ int handle_instance_remove(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_instance_remove_opts(char *prefix)
void autocomplete_instance_remove(void *args)
{
print_wargp_opts(remove_opts, prefix);
print_wargp_opts(remove_opts);
}

static struct wargp_option flush_opts[] = {
@@ -290,7 +292,7 @@ int handle_instance_flush(char *iname, int argc, char **argv, void *arg)
return error;
}

void print_instance_flush_opts(char *prefix)
void autocomplete_instance_flush(void *args)
{
print_wargp_opts(flush_opts, prefix);
print_wargp_opts(flush_opts);
}
@@ -6,9 +6,9 @@ int handle_instance_add(char *iname, int argc, char **argv, void *arg);
int handle_instance_remove(char *iname, int argc, char **argv, void *arg);
int handle_instance_flush(char *iname, int argc, char **argv, void *arg);

void print_instance_display_opts(char *prefix);
void print_instance_add_opts(char *prefix);
void print_instance_remove_opts(char *prefix);
void print_instance_flush_opts(char *prefix);
void autocomplete_instance_display(void *args);
void autocomplete_instance_add(void *args);
void autocomplete_instance_remove(void *args);
void autocomplete_instance_flush(void *args);

#endif /* SRC_USERSPACE_CLIENT_ARGP_INSTANCE_H_ */
Oops, something went wrong.

0 comments on commit 0557f39

Please sign in to comment.