Skip to content

allow non-interactive CLI commands#1333

Merged
Fredi-raspall merged 1 commit intomainfrom
pr/fredi/cli-non-interactive
Mar 11, 2026
Merged

allow non-interactive CLI commands#1333
Fredi-raspall merged 1 commit intomainfrom
pr/fredi/cli-non-interactive

Conversation

@Fredi-raspall
Copy link
Contributor

  • Allow invoking the cli in non-interactive mode, indicating the command to be executed
  • This was requested a long ago by @pau-hedgehog
  • One or more commands can be provided

Sample input

dataplane-cli  -c "show vrf" -c "show interface" -c "show ip route vrfid=0" -c "show router events"

Sample output

dataplane(✔)# show vrf

 ─────────────────────────────────── VRFs (4)  ───────────────────────────────────
            name       id      vni  Ipv4-routes  Ipv6-routes   status table-id description
       AAAAA-vrf       17     3000            7            1   active     3000 VPC-1
       CCCCC-vrf       14     2000            5            1   active     2000 VPC-3
       BBBBB-vrf       20     4000            7            1   active     4000 VPC-2
         default        0        0           16            1   active       -- 

dataplane(✔)# show interface

 ──────────────────────────────── interfaces (4)  ────────────────────────────────
 name               id    mtu AdmStatus OpStatus  attachment           type
 eth2               50   1500 up        unknown   VRF: vrfid: 0        Ethernet        mac:16:ad:78:b4:5f:99
 eth1               59   1500 up        unknown   VRF: vrfid: 0        Ethernet        mac:16:eb:8a:df:64:cb
 lo                  1     -- up        unknown   VRF: vrfid: 0        Loopback        
 eth0               48   1500 up        unknown   VRF: vrfid: 0        Ethernet        mac:5e:e6:16:90:7d:cb

dataplane(✔)# show ip route vrfid=0

 ━━━━━━━━━
 Vrf: 'default' (id: 0) description: --
 ─────────────────────────────── Ipv4 routes (16)  ───────────────────────────────
   0.0.0.0/0 other [0/0] 00:38:59
        action Drop
   7.0.0.1/32 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
        via 10.0.1.13 interface eth2 (idx 50)
   7.0.0.2/32 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
   7.0.0.3/32 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
        via 10.0.1.13 interface eth2 (idx 50)
   7.0.0.4/32 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
        via 10.0.1.13 interface eth2 (idx 50)
   7.0.0.5/32 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
        via 10.0.1.13 interface eth2 (idx 50)
   7.0.0.6/32 bgp [20/0] 00:12:54
        via 10.0.1.13 interface eth2 (idx 50)
   7.0.0.100/32 local [0/0] 00:13:00
        interface lo (idx 1)
   10.0.0.12/30 connected [0/0] 00:13:00
        interface eth0 (idx 48)
   10.0.0.14/32 local [0/0] 00:13:00
        interface eth0 (idx 48)
   10.0.1.12/30 connected [0/0] 00:13:00
        interface eth2 (idx 50)
   10.0.1.14/32 local [0/0] 00:13:00
        interface eth2 (idx 50)
   13.13.13.0/29 bgp [20/0] 00:12:54
        via 10.0.0.13 interface eth0 (idx 48)
        via 10.0.1.13 interface eth2 (idx 50)
   99.99.0.0/16 bgp [20/0] 00:12:54
        via 10.0.1.13 interface eth2 (idx 50)
   172.16.0.0/24 connected [0/0] 00:13:00
        interface eth1 (idx 59)
   172.16.0.1/32 local [0/0] 00:13:00
        interface eth1 (idx 59)

dataplane(✔)# show router events
 ROUTER_EVENTS
 generated: 7 stored: 7 capacity: 1000
 ━━━━━━━━━━━━━
 0    2026-03-11T 08:58:20: Started!
 1    2026-03-11T 08:58:21: Connected to frr-agent
 2    2026-03-11T 09:23:37: CPI status changed to Connected
 3    2026-03-11T 09:24:18: Router config request received for generation 2
 4    2026-03-11T 09:24:18: Router config request for generation 2 SUCCEEDED
 5    2026-03-11T 09:24:19: Requested FRR configuration for generation 2
 6    2026-03-11T 09:24:19: FRR configuration for generation 2 SUCCEEDED

Allow invoking the cli in non-interactive mode, indicating the
command to be executed. E.g.

    cli --command "show ip route"
or:
    cli -c "show ip route"

Multiple commands can be provided, with arguments. E.g.

    cli -c "show vrf" -c "show ip route vrrfid=0"

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
@Fredi-raspall Fredi-raspall requested a review from a team as a code owner March 11, 2026 09:39
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! If it were me, I'd even go as far as make non-interactive the default 👼

node.show_children();
}
} else {
print_err!("syntax error");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: case consistency (even though I see it's code you moved)

Suggested change
print_err!("syntax error");
print_err!("Syntax error");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll check that later. There's another PR.

@Fredi-raspall
Copy link
Contributor Author

Looks great! If it were me, I'd even go as far as make non-interactive the default 👼

But then we would not have the completions, which are very handy IMO.

@Fredi-raspall Fredi-raspall added this pull request to the merge queue Mar 11, 2026
@qmonnet
Copy link
Member

qmonnet commented Mar 11, 2026

But then we would not have the completions, which are very handy IMO.

True, but we'd still have them when invoking the interactive mode (as opt-in), or by loading a bash completion script (but we'd need to create that first).

Merged via the queue into main with commit 5eafb11 Mar 11, 2026
21 checks passed
@Fredi-raspall Fredi-raspall deleted the pr/fredi/cli-non-interactive branch March 11, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants