Closed stuartlynn closed 2 months ago
Example command to run
cargo run -- data --bbox 12,5,3,4 -m E0034,E444,E343
Gives the result
You selected the Data command DataArgs {
bbox: Some(
BBox(
[
12.0,
5.0,
3.0,
4.0,
],
),
),
metrics: Some(
"E0034,E444,E343",
),
}
Last push added a pattern for running command more ergonomically.
Now we declare a trait RunCommand:
#[enum_dispatch]
pub trait RunCommand{
fn run(&self)->Result<()>;
}
which each Command needs to implement. We then just invoke command.run() in the main.rs entrypoint to run the command. For example
impl RunCommand for DataCommand{
fn run(&self)->Result<()> {
println!("Running Data Command");
println!("{self:#?}");
Ok(())
}
}
In addition I stubbed out a lib struct to start to represent a data request. We have implemented From<DataCommand> for DataRequestSpec
. This will probably grow and change in time but is a good starting point for now.
impl From<DataCommand> for DataRequestSpec{
fn from(value: DataCommand) -> Self {
let region = if let Some(bbox) = value.bbox{
vec![RegionSpec::BoundingBox(bbox)]
}
else{
vec![]
};
let metrics = vec![];
DataRequestSpec{
region,
metrics
}
}
}
Thanks @yongrenjie accepted those changes.
Also, presumably when it's all fleshed out we might want to eventually separate the commands out into their own modules?
I think this makes sense but seems a bit premature just now. I am hoping most of them will end up being simple calls to the library functions so we can capture most of the complexity in there.
I feel like the spurious FromStr warning should be reported upstream if it isn't already
Yeah this is a weird one. Not sure who to report it (probably rust-analyser?) to or even how to describe the bug .
Macros are too magic :)
I think it's this issue here: https://github.com/rust-lang/rust-analyzer/issues/15501
TODO