cli: consolidate active and configured connections (rh #997999)
Handle connection profiles in a single 'show' command instead of 'show active' and 'show configured'. nmcli con show [--active] [[id|uuid|path|apath] <bla>] nmcli con show : display all connection profiles nmcli con show --active : only display active connection profiles (filters out inactive profiles) nmcli con show myeth : display details of "myeth" profile, and also active connection info (if the profile is active) nmcli -f profile con show myeth : only display "myeth"'s static configuration nmcli -f active con show myeth : only display active details of "myeth" nmcli -f connection.id,ipv4,general con show myeth : display "connection.id"a property "ipv4" setting and "GENERAL" group of active data https://bugzilla.redhat.com/show_bug.cgi?id=997999
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2010 - 2013 Red Hat, Inc.
|
||||
* (C) Copyright 2010 - 2014 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
/* Generated configuration file */
|
||||
@@ -72,6 +72,23 @@ nmc_arg_is_help (const char *arg)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmc_arg_is_option (const char *str, const char *opt_name)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (!str || !*str)
|
||||
return FALSE;
|
||||
|
||||
if (str[0] != '-')
|
||||
return FALSE;
|
||||
|
||||
p = (str[1] == '-') ? str + 2 : str + 1;
|
||||
|
||||
return (*p ? (matches (p, opt_name) == 0) : FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to parse command-line arguments.
|
||||
* arg_arr: description of arguments to look for
|
||||
@@ -699,27 +716,15 @@ parse_output_fields (const char *fields_str,
|
||||
|
||||
/* Field was not found - error case */
|
||||
if (fields_array[i].name == NULL) {
|
||||
GString *allowed_fields = g_string_sized_new (256);
|
||||
int k;
|
||||
|
||||
/* Set GError */
|
||||
if (idx != -1 && fields_array[idx].group) {
|
||||
NmcOutputField *second_level = fields_array[idx].group;
|
||||
for (k = 0; second_level[k].name; k++)
|
||||
g_string_append_printf (allowed_fields, "%s.%s,",
|
||||
fields_array[idx].name, second_level[k].name);
|
||||
} else {
|
||||
for (k = 0; fields_array[k].name; k++)
|
||||
g_string_append_printf (allowed_fields, "%s,", fields_array[k].name);
|
||||
}
|
||||
g_string_truncate (allowed_fields, allowed_fields->len - 1);
|
||||
|
||||
if (!strcasecmp (*iter, "all") || !strcasecmp (*iter, "common"))
|
||||
g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), *iter);
|
||||
else
|
||||
else {
|
||||
char *allowed_fields = nmc_get_allowed_fields (fields_array, idx);
|
||||
g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s'; allowed fields: %s"),
|
||||
*iter, allowed_fields->str);
|
||||
g_string_free (allowed_fields, TRUE);
|
||||
*iter, allowed_fields);
|
||||
g_free (allowed_fields);
|
||||
}
|
||||
|
||||
/* Free arrays on error */
|
||||
g_array_free (array, TRUE);
|
||||
@@ -737,6 +742,35 @@ done:
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* nmc_get_allowed_fields:
|
||||
* @fields_array: array of fields
|
||||
* @group_idx: index to the array (for second-level array in 'group' member),
|
||||
* or -1
|
||||
*
|
||||
* Returns: string of allowed fields names.
|
||||
* Caller is responsible for freeing the array.
|
||||
*/
|
||||
char *
|
||||
nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx)
|
||||
{
|
||||
GString *allowed_fields = g_string_sized_new (256);
|
||||
int i;
|
||||
|
||||
if (group_idx != -1 && fields_array[group_idx].group) {
|
||||
NmcOutputField *second_level = fields_array[group_idx].group;
|
||||
for (i = 0; second_level[i].name; i++)
|
||||
g_string_append_printf (allowed_fields, "%s.%s,",
|
||||
fields_array[group_idx].name, second_level[i].name);
|
||||
} else {
|
||||
for (i = 0; fields_array[i].name; i++)
|
||||
g_string_append_printf (allowed_fields, "%s,", fields_array[i].name);
|
||||
}
|
||||
g_string_truncate (allowed_fields, allowed_fields->len - 1);
|
||||
|
||||
return g_string_free (allowed_fields, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmc_terse_option_check (NMCPrintOutput print_output, const char *fields, GError **error)
|
||||
{
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2010 - 2013 Red Hat, Inc.
|
||||
* (C) Copyright 2010 - 2014 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NMC_UTILS_H
|
||||
@@ -38,6 +38,7 @@ typedef struct {
|
||||
int matches (const char *cmd, const char *pattern);
|
||||
int next_arg (int *argc, char ***argv);
|
||||
gboolean nmc_arg_is_help (const char *arg);
|
||||
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
|
||||
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GError **error);
|
||||
char *ssid_to_hex (const char *str, gsize len);
|
||||
gboolean nmc_string_to_int_base (const char *str,
|
||||
@@ -85,6 +86,7 @@ GArray *parse_output_fields (const char *fields_str,
|
||||
gboolean parse_groups,
|
||||
GPtrArray **group_fields,
|
||||
GError **error);
|
||||
char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx);
|
||||
gboolean nmc_terse_option_check (NMCPrintOutput print_output, const char *fields, GError **error);
|
||||
NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags);
|
||||
void nmc_empty_output_fields (NmCli *nmc);
|
||||
|
Reference in New Issue
Block a user