@@ -7,7 +7,7 @@ use std::{
77} ;
88
99use anyhow:: { Result , bail} ;
10- use clap:: { Parser , Subcommand } ;
10+ use clap:: { CommandFactory , Parser , Subcommand } ;
1111use fabric:: {
1212 config:: {
1313 FabricHome , PeerBook , generate_identity_file, load_or_create_identity, parse_addr_json,
@@ -23,11 +23,14 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
2323#[ command( name = "fabric" ) ]
2424#[ command( about = "Local socket facade for iroh-backed cross-machine transports" ) ]
2525struct Cli {
26+ #[ arg( long) ]
27+ version : bool ,
28+
2629 #[ arg( long, global = true ) ]
2730 home : Option < PathBuf > ,
2831
2932 #[ command( subcommand) ]
30- command : Commands ,
33+ command : Option < Commands > ,
3134}
3235
3336#[ derive( Debug , Subcommand ) ]
@@ -99,8 +102,18 @@ enum KeyCommands {
99102#[ tokio:: main]
100103async fn main ( ) -> Result < ( ) > {
101104 let cli = Cli :: parse ( ) ;
105+ if cli. version {
106+ println ! ( "{}" , fabric:: version_string( ) ) ;
107+ return Ok ( ( ) ) ;
108+ }
109+
110+ let Some ( command) = cli. command else {
111+ Cli :: command ( ) . print_help ( ) ?;
112+ println ! ( ) ;
113+ return Ok ( ( ) ) ;
114+ } ;
102115
103- match cli . command {
116+ match command {
104117 Commands :: Key {
105118 command : KeyCommands :: Gen { out } ,
106119 } => {
@@ -124,13 +137,15 @@ async fn main() -> Result<()> {
124137 Commands :: Status => {
125138 match send_control ( & home, ControlRequest :: ReachabilityStatus ) . await ? {
126139 ControlResponse :: ReachabilityStatus {
140+ version,
127141 node_id,
128142 endpoint_addr,
129143 exposed_protocols,
130144 dial_sockets,
131145 peers,
132146 } => {
133147 print_status (
148+ & version,
134149 & node_id,
135150 & endpoint_addr,
136151 & exposed_protocols,
@@ -240,12 +255,14 @@ async fn main() -> Result<()> {
240255}
241256
242257fn print_status (
258+ version : & str ,
243259 node_id : & str ,
244260 endpoint_addr : & serde_json:: Value ,
245261 exposed_protocols : & [ String ] ,
246262 dial_sockets : & [ PathBuf ] ,
247263 peers : & [ PeerReachability ] ,
248264) -> Result < ( ) > {
265+ println ! ( "version\t {version}" ) ;
249266 println ! ( "node\t {node_id}" ) ;
250267 println ! ( "addr\t {}" , serde_json:: to_string( endpoint_addr) ?) ;
251268 println ! ( "exposed\t {}" , joined_or_dash( exposed_protocols) ) ;
0 commit comments