]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkctl: allow to call 'networkctl cat' without arguments
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Apr 2024 04:29:23 +0000 (13:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Apr 2024 04:31:14 +0000 (13:31 +0900)
Then, show networkd.conf and its drop-ins.

man/networkctl.xml
src/network/networkctl-config-file.c
src/network/networkctl.c

index 562ca3c6a7d1dcc609c32f05deddd0b5cb03d34a..5e2126ff218c7ea773f938f7e59f35901559c71f 100644 (file)
@@ -454,12 +454,16 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
       <varlistentry>
         <term>
           <command>cat</command>
-          <replaceable>FILE</replaceable>|<replaceable>@DEVICE</replaceable>…
+          <optional><replaceable>FILE</replaceable>|<replaceable>@DEVICE</replaceable>…</optional>
         </term>
-        <listitem><para>Show network configuration files. This command honors
-        the <literal>@</literal> prefix in the same way as <command>edit</command>.</para>
+        <listitem>
+          <para>Show network configuration files. This command honors the <literal>@</literal> prefix in the
+          same way as <command>edit</command>. When no argument is specified,
+          <citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+          and its drop-in files will be shown.</para>
 
-        <xi:include href="version-info.xml" xpointer="v254"/></listitem>
+          <xi:include href="version-info.xml" xpointer="v254"/>
+        </listitem>
       </varlistentry>
 
       <varlistentry>
index 670f1c2fd7b6cd250569ad23adb78431c3500f51..216e9d49543ffe45791ac7cb2a8cd37466bc9fc8 100644 (file)
@@ -476,12 +476,16 @@ int verb_edit(int argc, char *argv[], void *userdata) {
 
 int verb_cat(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
+        char **args = strv_skip(argv, 1);
         int r, ret = 0;
 
         pager_open(arg_pager_flags);
 
+        if (strv_isempty(args))
+                return conf_files_cat(NULL, "systemd/networkd.conf", CAT_FORMAT_HAS_SECTIONS);
+
         bool first = true;
-        STRV_FOREACH(name, strv_skip(argv, 1)) {
+        STRV_FOREACH(name, args) {
                 _cleanup_strv_free_ char **dropins = NULL;
                 _cleanup_free_ char *path = NULL;
                 const char *link_config;
index 56fa373b1d2418f86aa9cf655e384cacc31a2e76..46f7d5036927ba0d7e0043c02e2f047e6ccc6db6 100644 (file)
@@ -2982,7 +2982,7 @@ static int help(void) {
                "  reconfigure DEVICES... Reconfigure interfaces\n"
                "  reload                 Reload .network and .netdev files\n"
                "  edit FILES|DEVICES...  Edit network configuration files\n"
-               "  cat FILES|DEVICES...   Show network configuration files\n"
+               "  cat [FILES|DEVICES...] Show network configuration files\n"
                "  mask FILES...          Mask network configuration files\n"
                "  unmask FILES...        Unmask network configuration files\n"
                "  persistent-storage BOOL\n"
@@ -3142,7 +3142,7 @@ static int networkctl_main(int argc, char *argv[]) {
                 { "reconfigure",        2,        VERB_ANY, VERB_ONLINE_ONLY,              verb_reconfigure        },
                 { "reload",             1,        1,        VERB_ONLINE_ONLY,              verb_reload             },
                 { "edit",               2,        VERB_ANY, 0,                             verb_edit               },
-                { "cat",                2,        VERB_ANY, 0,                             verb_cat                },
+                { "cat",                1,        VERB_ANY, 0,                             verb_cat                },
                 { "mask",               2,        VERB_ANY, 0,                             verb_mask               },
                 { "unmask",             2,        VERB_ANY, 0,                             verb_unmask             },
                 { "persistent-storage", 2,        2,        0,                             verb_persistent_storage },