@@ -751,13 +751,24 @@ def onConnected(interface):
751751 interface .getNode (args .dest , False , ** getNode_kwargs ).commitSettingsTransaction ()
752752 print ("Writing modified configuration to device" )
753753
754- if args .export_config :
754+ if args .export_config is not None :
755755 if args .dest != BROADCAST_ADDR :
756756 print ("Exporting configuration of remote nodes is not supported." )
757757 return
758- # export the configuration (the opposite of '--configure')
758+
759759 closeNow = True
760- export_config (interface )
760+ config_txt = export_config (interface )
761+
762+ if args .export_config == "-" :
763+ # Output to stdout (preserves legacy use of `> file.yaml`)
764+ print (config_txt )
765+ else :
766+ try :
767+ with open (args .export_config , "w" , encoding = "utf-8" ) as f :
768+ f .write (config_txt )
769+ print (f"Exported configuration to { args .export_config } " )
770+ except Exception as e :
771+ meshtastic .util .our_exit (f"ERROR: Failed to write config file: { e } " )
761772
762773 if args .ch_set_url :
763774 closeNow = True
@@ -1160,7 +1171,6 @@ def export_config(interface) -> str:
11601171 config_txt = "# start of Meshtastic configure yaml\n " #checkme - "config" (now changed to config_out)
11611172 #was used as a string here and a Dictionary above
11621173 config_txt += yaml .dump (configObj )
1163- print (config_txt )
11641174 return config_txt
11651175
11661176
@@ -1458,10 +1468,12 @@ def addImportExportArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar
14581468 help = "Specify a path to a yaml(.yml) file containing the desired settings for the connected device." ,
14591469 action = "append" ,
14601470 )
1461- group .add_argument (
1471+ parser .add_argument (
14621472 "--export-config" ,
1463- help = "Export the configuration in yaml(.yml) format." ,
1464- action = "store_true" ,
1473+ nargs = "?" ,
1474+ const = "-" , # default to "-" if no value provided
1475+ metavar = "FILE" ,
1476+ help = "Export device config as YAML (to stdout if no file given)"
14651477 )
14661478 return parser
14671479
0 commit comments