flatpak ps: Match uniqe prefixes of column names

So much more convenient to say 'app' than 'application'.

Closes: #2027
Approved by: alexlarsson
This commit is contained in:
Matthias Clasen
2018-08-27 13:09:14 -04:00
committed by Atomic Bot
parent ad49ca758c
commit 03bb003f0f
2 changed files with 30 additions and 5 deletions

View File

@@ -64,16 +64,37 @@ static struct {
#define DEFAULT_COLUMNS "pid,application,runtime"
static int
find_column (const char *name)
find_column (const char *name,
GError **error)
{
int i;
int candidate;
candidate = -1;
for (i = 0; i < G_N_ELEMENTS(all_columns); i++)
{
if (strcmp (name, all_columns[i].name) == 0)
return i;
if (g_str_equal (all_columns[i].name, name))
{
return i;
}
else if (g_str_has_prefix (all_columns[i].name, name))
{
if (candidate == -1)
{
candidate = i;
}
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Ambiguous column: %s"), name);
return -1;
}
}
}
if (candidate >= 0)
return candidate;
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unknown colum: %s"), name);
return -1;
}
@@ -196,10 +217,9 @@ enumerate_instances (const char *columns,
col_idx = g_new (int, n_cols);
for (i = 0; i < n_cols; i++)
{
col_idx[i] = find_column (cols[i]);
col_idx[i] = find_column (cols[i], error);
if (col_idx[i] == -1)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unknown colum: %s"), cols[i]);
return FALSE;
}
}

View File

@@ -187,6 +187,11 @@
</para></listitem>
</varlistentry>
</variablelist>
<para>
Note that field names can be abbreviated to a unique prefix.
</para>
</refsect1>
<refsect1>