File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -755,9 +755,20 @@ def onConnected(interface):
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
@@ -1460,8 +1470,10 @@ def addImportExportArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar
14601470 )
14611471 group .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
Original file line number Diff line number Diff line change @@ -1738,7 +1738,8 @@ def test_main_export_config(capsys):
17381738fixed_position: true
17391739position_flags: 35"""
17401740 export_config (mo )
1741- out , err = capsys .readouterr ()
1741+ out = export_config (mo )
1742+ err = ""
17421743
17431744 # ensure we do not output this line
17441745 assert not re .search (r"Connected to radio" , out , re .MULTILINE )
You can’t perform that action at this time.
0 commit comments