cli: by default, assume output filename is input's with .ses extension

This commit is contained in:
Mikolaj Wielgus 2024-07-16 16:46:02 +02:00
parent 87fd5d5d05
commit a9f42e1d8f
2 changed files with 14 additions and 7 deletions

View File

@ -42,14 +42,17 @@ The application will now be invokable from your terminal as `topola`.
#### Autorouting example #### Autorouting example
As an example, running the following commands will autoroute a KiCad project of a As an example, running the following commands will autoroute a KiCad
simple THT diode bridge rectifier: project of a simple THT diode bridge rectifier:
``` ```
cd tests/single_layer/data/tht_diode_bridge_rectifier/ cd tests/single_layer/data/tht_diode_bridge_rectifier/
topola tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses topola tht_diode_bridge_rectifier.dsn
``` ```
By default, the output filename is the input filename with extension
changed to `ses`: `tht_diode_bridge_rectifier.ses`.
##### Viewing the results ##### Viewing the results
You can view the results of the autorouting in KiCad if you have it You can view the results of the autorouting in KiCad if you have it
@ -72,7 +75,7 @@ then as follows:
``` ```
cd tests/single_layer/data/tht_diode_bridge_rectifier/ cd tests/single_layer/data/tht_diode_bridge_rectifier/
cargo run --features cli -- tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses cargo run --features cli -- tht_diode_bridge_rectifier.dsn
``` ```
Viewing the results is obviously the same. Viewing the results is obviously the same.

View File

@ -14,7 +14,8 @@ use topola::specctra::design::SpecctraDesign;
#[command(about, version)] #[command(about, version)]
struct Cli { struct Cli {
input: PathBuf, input: PathBuf,
output: PathBuf, #[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
#[arg(short, long, value_name = "FILE")] #[arg(short, long, value_name = "FILE")]
commands: Option<PathBuf>, commands: Option<PathBuf>,
} }
@ -22,7 +23,7 @@ struct Cli {
fn main() -> Result<(), std::io::Error> { fn main() -> Result<(), std::io::Error> {
let args = Cli::parse(); let args = Cli::parse();
let design_file = File::open(args.input)?; let design_file = File::open(&args.input)?;
let mut design_bufread = BufReader::new(design_file); let mut design_bufread = BufReader::new(design_file);
let design = SpecctraDesign::load(design_bufread).unwrap(); let design = SpecctraDesign::load(design_bufread).unwrap();
@ -41,7 +42,10 @@ fn main() -> Result<(), std::io::Error> {
let mut invoker = Invoker::new(Autorouter::new(board).unwrap()); let mut invoker = Invoker::new(Autorouter::new(board).unwrap());
invoker.replay(history); invoker.replay(history);
let mut file = File::create(args.output).unwrap(); let output_filename = args
.output
.unwrap_or_else(|| args.input.clone().with_extension("ses"));
let mut file = File::create(output_filename).unwrap();
design.write_ses(invoker.autorouter().board(), &mut file); design.write_ses(invoker.autorouter().board(), &mut file);
Ok(()) Ok(())