@@ -608,24 +608,38 @@ def commands_callback(value: bool):
608
608
609
609
def debug_callback (value : bool ):
610
610
if value :
611
+ debug_file_loc = Path (
612
+ os .getenv ("BTCLI_DEBUG_FILE" )
613
+ or os .path .expanduser (defaults .config .debug_file_path )
614
+ )
615
+ if not debug_file_loc .exists ():
616
+ err_console .print (
617
+ f"[red]Error: The debug file '{ arg__ (str (debug_file_loc ))} ' does not exist. This indicates that you have"
618
+ f" not run a command which has logged debug output, or you deleted this file. Debug logging only occurs"
619
+ f" if { arg__ ('use_cache' )} is set to True in your config ({ arg__ ('btcli config set' )} ). If the debug "
620
+ f"file was created using the { arg__ ('BTCLI_DEBUG_FILE' )} environment variable, please set the value for"
621
+ f" the same location, and re-run this { arg__ ('btcli --debug' )} command.[/red]"
622
+ )
623
+ raise typer .Exit ()
611
624
save_file_loc_ = Prompt .ask (
612
625
"Enter the file location to save the debug log for the previous command." ,
613
626
default = "~/.bittensor/debug-export" ,
614
627
).strip ()
615
- save_file_loc = os .path .expanduser (save_file_loc_ )
628
+ save_file_loc = Path (os .path .expanduser (save_file_loc_ ))
629
+ if not save_file_loc .parent .exists ():
630
+ if Confirm .ask (
631
+ f"The directory '{ save_file_loc .parent } ' does not exist. Would you like to create it?"
632
+ ):
633
+ save_file_loc .parent .mkdir (parents = True , exist_ok = True )
616
634
try :
617
635
with (
618
636
open (save_file_loc , "w+" ) as save_file ,
619
- open (
620
- os .getenv ("BTCLI_DEBUG_FILE" )
621
- or os .path .expanduser (defaults .config .debug_file_path ),
622
- "r" ,
623
- ) as current_file ,
637
+ open (debug_file_loc , "r" ) as current_file ,
624
638
):
625
639
save_file .write (current_file .read ())
626
640
console .print (f"Saved debug log to { save_file_loc } " )
627
- except FileNotFoundError :
628
- print_error (f"The filepath ' { save_file_loc } ' does not exist." )
641
+ except FileNotFoundError as e :
642
+ print_error (str ( e ) )
629
643
raise typer .Exit ()
630
644
631
645
@@ -1243,7 +1257,7 @@ def main_callback(
1243
1257
):
1244
1258
"""
1245
1259
Command line interface (CLI) for Bittensor. Uses the values in the configuration file. These values can be
1246
- overriden by passing them explicitly in the command line.
1260
+ overridden by passing them explicitly in the command line.
1247
1261
"""
1248
1262
# Load or create the config file
1249
1263
if os .path .exists (self .config_path ):
@@ -1267,6 +1281,9 @@ def main_callback(
1267
1281
if sub_key not in config [key ]:
1268
1282
config [key ][sub_key ] = sub_value
1269
1283
updated = True
1284
+ elif isinstance (value , bool ) and config [key ] is None :
1285
+ config [key ] = value
1286
+ updated = True
1270
1287
if updated :
1271
1288
with open (self .config_path , "w" ) as f :
1272
1289
safe_dump (config , f )
0 commit comments