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

Various CLI improvements #2811

Merged
merged 8 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-archivez.sh \
tests/test-remote-add.sh \
tests/test-remote-headers.sh \
tests/test-remote-refs.sh \
tests/test-commit-sign.sh \
tests/test-commit-timestamp.sh \
tests/test-export.sh \
Expand Down
20 changes: 14 additions & 6 deletions bash/ostree
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ _ostree_pull() {
local boolean_options="
$main_boolean_options
--commit-metadata-only
--cache-dir
--disable-fsync
--disable-static-deltas
--require-static-deltas
Expand All @@ -912,6 +911,7 @@ _ostree_pull() {
"

local options_with_args="
--cache-dir
--depth
--http-header
--localcache-repo -L
Expand All @@ -925,7 +925,7 @@ _ostree_pull() {
local options_with_args_glob=$( __ostree_to_extglob "$options_with_args" )

case "$prev" in
--localcache-repo|-L|--repo|--subpath)
--cache-dir|--localcache-repo|-L|--repo|--subpath)
__ostree_compreply_dirs_only
return 0
;;
Expand Down Expand Up @@ -953,6 +953,7 @@ _ostree_pull() {
_ostree_refs() {
local boolean_options="
$main_boolean_options
--revision -r
--alias -A
--collections -c
--delete
Expand Down Expand Up @@ -1274,17 +1275,18 @@ _ostree_remote_list_gpg_keys() {
_ostree_remote_refs() {
local boolean_options="
$main_boolean_options
--cache-dir
--revision -r
"

local options_with_args="
--cache-dir
--repo
"

local options_with_args_glob=$( __ostree_to_extglob "$options_with_args" )

case "$prev" in
--repo)
--cache-dir|--repo)
__ostree_compreply_dirs_only
return 0
;;
Expand Down Expand Up @@ -1343,18 +1345,20 @@ _ostree_remote_show_url() {
_ostree_remote_summary() {
local boolean_options="
$main_boolean_options
--cache-dir
--list-metadata-keys
--raw
"

local options_with_args="
--cache-dir
--print-metadata-key
--repo
"

local options_with_args_glob=$( __ostree_to_extglob "$options_with_args" )

case "$prev" in
--repo)
--cache-dir|--repo)
__ostree_compreply_dirs_only
return 0
;;
Expand Down Expand Up @@ -1484,6 +1488,8 @@ _ostree_rev_parse() {
_ostree_show() {
local boolean_options="
$main_boolean_options
--list-detached-metadata-keys
--list-metadata-keys
--print-related
--print-sizes
--raw
Expand Down Expand Up @@ -1812,6 +1818,7 @@ _ostree_static_delta() {
_ostree_summary() {
local boolean_options="
$main_boolean_options
--list-metadata-keys
--raw
--update -u
--view -v
Expand All @@ -1821,6 +1828,7 @@ _ostree_summary() {
--add-metadata -m
--gpg-homedir
--gpg-sign
--print-metadata-key
--repo
"

Expand Down
8 changes: 8 additions & 0 deletions man/ostree-find-remotes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
<title>Options</title>

<variablelist>
<varlistentry>
<term><option>--cache-dir</option>=DIR</term>

<listitem><para>
Use an alternate cache directory in <literal>DIR</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--disable-fsync</option></term>

Expand Down
8 changes: 8 additions & 0 deletions man/ostree-pull.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--cache-dir</option>=DIR</term>

<listitem><para>
Use an alternate cache directory in <literal>DIR</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--disable-fsync</option></term>

Expand Down
9 changes: 9 additions & 0 deletions man/ostree-refs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--revision</option>, <option>-r</option></term>

<listitem><para>
When listing refs, also print their revisions. The revisions
will be separated by a tab character.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--alias</option>, <option>-A</option></term>

Expand Down
33 changes: 33 additions & 0 deletions man/ostree-remote.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,31 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</variablelist>
</refsect1>

<refsect1>
<title>'Refs' Options</title>

<variablelist>
<varlistentry>
<term><option>--revision</option>, <option>-r</option></term>

<listitem><para>
Also print the revisions for each ref. The revisions will
be separated by a tab character.
</para></listitem>
</varlistentry>
</variablelist>

<variablelist>
<varlistentry>
<term><option>--cache-dir</option>=DIR</term>

<listitem><para>
Use an alternate cache directory in <literal>DIR</literal>.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1>
<title>'GPG-Import' Options</title>

Expand Down Expand Up @@ -226,6 +251,14 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
<title>'Summary' Options</title>

<variablelist>
<varlistentry>
<term><option>--cache-dir</option>=DIR</term>

<listitem><para>
Use an alternate cache directory in <literal>DIR</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--raw</option></term>

Expand Down
16 changes: 16 additions & 0 deletions man/ostree-show.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--list-metadata-keys</option></term>

<listitem><para>
List the available metadata keys.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--print-metadata-key</option>="KEY"</term>

Expand All @@ -89,6 +97,14 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--list-detached-metadata-keys</option></term>

<listitem><para>
List the available detached metadata keys.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--print-detached-metadata-key</option>="KEY"</term>

Expand Down
52 changes: 45 additions & 7 deletions src/ostree/ot-builtin-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

static gboolean opt_delete;
static gboolean opt_list;
static gboolean opt_revision;
static gboolean opt_alias;
static char *opt_create;
static gboolean opt_collections;
Expand All @@ -40,13 +41,24 @@ static gboolean opt_force;
static GOptionEntry options[] = {
{ "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL },
{ "list", 0, 0, G_OPTION_ARG_NONE, &opt_list, "Do not remove the prefix from the refs", NULL },
{ "revision", 'r', 0, G_OPTION_ARG_NONE, &opt_revision, "Show revisions in listing", NULL },
{ "alias", 'A', 0, G_OPTION_ARG_NONE, &opt_alias, "If used with --create, create an alias, otherwise just list aliases", NULL },
{ "create", 0, 0, G_OPTION_ARG_STRING, &opt_create, "Create a new ref for an existing commit", "NEWREF" },
{ "collections", 'c', 0, G_OPTION_ARG_NONE, &opt_collections, "Enable listing collection IDs for refs", NULL },
{ "force", 0, 0, G_OPTION_ARG_NONE, &opt_force, "Overwrite existing refs when creating", NULL },
{ NULL }
};

static int
collection_ref_cmp (OstreeCollectionRef *a,
OstreeCollectionRef *b)
{
int ret = g_strcmp0 (a->collection_id, b->collection_id);
if (ret == 0)
ret = g_strcmp0 (a->ref_name, b->ref_name);
return ret;
}

static gboolean
do_ref_with_collections (OstreeRepo *repo,
const char *refspec_prefix,
Expand All @@ -66,11 +78,22 @@ do_ref_with_collections (OstreeRepo *repo,

if (!opt_delete && !opt_create)
{
g_hash_table_iter_init (&hashiter, refs);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs);
ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) collection_ref_cmp);

for (GList *iter = ordered_keys; iter != NULL; iter = iter->next)
{
const OstreeCollectionRef *ref = hashkey;
g_print ("(%s, %s)\n", ref->collection_id, ref->ref_name);
OstreeCollectionRef *ref = iter->data;

if (opt_revision)
{
const char *rev = g_hash_table_lookup (refs, ref);
g_print ("(%s, %s)\t%s\n", ref->collection_id, ref->ref_name, rev);
}
else
{
g_print ("(%s, %s)\n", ref->collection_id, ref->ref_name);
}
}
}
else if (opt_create)
Expand Down Expand Up @@ -179,12 +202,27 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab

if (is_list)
{
GLNX_HASH_TABLE_FOREACH_KV (refs, const char *, ref, const char *, value)
g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs);
ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) g_strcmp0);

for (GList *iter = ordered_keys; iter != NULL; iter = iter->next)
{
const char *ref = iter->data;

if (opt_alias)
g_print ("%s -> %s\n", ref, value);
{
const char *alias = g_hash_table_lookup (refs, ref);
g_print ("%s -> %s\n", ref, alias);
jlebon marked this conversation as resolved.
Show resolved Hide resolved
}
else if (opt_revision)
{
const char *rev = g_hash_table_lookup (refs, ref);
g_print ("%s\t%s\n", ref, rev);
}
else
g_print ("%s\n", ref);
{
g_print ("%s\n", ref);
}
}
}
else if (opt_create)
Expand Down
Loading