|
@@ -20,8 +20,8 @@ use crate::{
|
|
|
Error,
|
|
|
};
|
|
|
|
|
|
-mod parse;
|
|
|
mod eval;
|
|
|
+mod parse;
|
|
|
|
|
|
/// Trait used to expose errors from the autogenerated clap interface code. Implemented for
|
|
|
/// [`Error`] but can be implemented for other error types if extra information needs to be passed
|
|
@@ -59,19 +59,35 @@ pub trait EntityInterface {
|
|
|
type CustomCommand: clap::Subcommand + std::fmt::Debug;
|
|
|
|
|
|
/// Invoked when a custom command is parsed.
|
|
|
- fn run_custom(ctx: &Self::Context, cmd: Self::CustomCommand, query_ctx: impl Queryable<EntityOutput = Self::Entity>, insert_ctx: &impl Insertable<Self::Entity>) -> Result<(), Self::Error>;
|
|
|
+ fn run_custom(
|
|
|
+ ctx: &Self::Context,
|
|
|
+ cmd: Self::CustomCommand,
|
|
|
+ query_ctx: impl Queryable<EntityOutput = Self::Entity>,
|
|
|
+ insert_ctx: &impl Insertable<Self::Entity>,
|
|
|
+ ) -> Result<(), Self::Error>;
|
|
|
|
|
|
/// Provide a summary of the entity, ideally a string with no newlines that can identify the
|
|
|
/// entity at a glance.
|
|
|
- fn summarize(_: &Self::Entity) -> Option<String> { None }
|
|
|
+ fn summarize(_: &Self::Entity) -> Option<String> {
|
|
|
+ None
|
|
|
+ }
|
|
|
|
|
|
/// Provided to allow overriding the value passed to autogenerated commands, so that it is not
|
|
|
/// requested on the command-line.
|
|
|
- fn should_override(_entity: &'static str, _field: &'static str, _role: ValueRole) -> bool { false }
|
|
|
-
|
|
|
+ fn should_override(_entity: &'static str, _field: &'static str, _role: ValueRole) -> bool {
|
|
|
+ false
|
|
|
+ }
|
|
|
+
|
|
|
/// Invoked to request the concrete value for a value. Will only be invoked if
|
|
|
/// should_override() for the same parameters previously returned true.
|
|
|
- fn override_for(_ctx: &Self::Context, _entity: &'static str, _field: &'static str, _role: ValueRole) -> String { unreachable!() }
|
|
|
+ fn override_for(
|
|
|
+ _ctx: &Self::Context,
|
|
|
+ _entity: &'static str,
|
|
|
+ _field: &'static str,
|
|
|
+ _role: ValueRole,
|
|
|
+ ) -> String {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// Empty subcommand, used as a default value for CLIObjects that have no implemented additional
|
|
@@ -167,12 +183,9 @@ mod tests {
|
|
|
transactions: microrm::IDMap<Transaction>,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
#[derive(Debug, clap::Subcommand)]
|
|
|
enum CCustom {
|
|
|
- Create {
|
|
|
- name: String,
|
|
|
- }
|
|
|
+ Create { name: String },
|
|
|
}
|
|
|
|
|
|
#[derive(Debug)]
|
|
@@ -183,10 +196,18 @@ mod tests {
|
|
|
type Context = ();
|
|
|
|
|
|
type CustomCommand = CCustom;
|
|
|
- fn run_custom(_ctx: &Self::Context, cmd: Self::CustomCommand, _query_ctx: impl Queryable<EntityOutput = Self::Entity>, insert_ctx: &impl Insertable<Self::Entity>) -> Result<(), Self::Error> {
|
|
|
+ fn run_custom(
|
|
|
+ _ctx: &Self::Context,
|
|
|
+ cmd: Self::CustomCommand,
|
|
|
+ _query_ctx: impl Queryable<EntityOutput = Self::Entity>,
|
|
|
+ insert_ctx: &impl Insertable<Self::Entity>,
|
|
|
+ ) -> Result<(), Self::Error> {
|
|
|
match cmd {
|
|
|
CCustom::Create { name } => {
|
|
|
- insert_ctx.insert(Customer { name, txs: Default::default() })?;
|
|
|
+ insert_ctx.insert(Customer {
|
|
|
+ name,
|
|
|
+ txs: Default::default(),
|
|
|
+ })?;
|
|
|
},
|
|
|
}
|
|
|
Ok(())
|
|
@@ -195,9 +216,7 @@ mod tests {
|
|
|
|
|
|
#[derive(Debug, clap::Subcommand)]
|
|
|
enum ECustom {
|
|
|
- Create {
|
|
|
- name: String,
|
|
|
- }
|
|
|
+ Create { name: String },
|
|
|
}
|
|
|
|
|
|
#[derive(Debug)]
|
|
@@ -208,10 +227,18 @@ mod tests {
|
|
|
type Context = ();
|
|
|
|
|
|
type CustomCommand = ECustom;
|
|
|
- fn run_custom(_ctx: &Self::Context, cmd: Self::CustomCommand, _query_ctx: impl Queryable<EntityOutput = Self::Entity>, insert_ctx: &impl Insertable<Self::Entity>) -> Result<(), Self::Error> {
|
|
|
+ fn run_custom(
|
|
|
+ _ctx: &Self::Context,
|
|
|
+ cmd: Self::CustomCommand,
|
|
|
+ _query_ctx: impl Queryable<EntityOutput = Self::Entity>,
|
|
|
+ insert_ctx: &impl Insertable<Self::Entity>,
|
|
|
+ ) -> Result<(), Self::Error> {
|
|
|
match cmd {
|
|
|
ECustom::Create { name } => {
|
|
|
- insert_ctx.insert(Employee { name, txs: Default::default() })?;
|
|
|
+ insert_ctx.insert(Employee {
|
|
|
+ name,
|
|
|
+ txs: Default::default(),
|
|
|
+ })?;
|
|
|
},
|
|
|
}
|
|
|
Ok(())
|
|
@@ -220,10 +247,7 @@ mod tests {
|
|
|
|
|
|
#[derive(Debug, clap::Subcommand)]
|
|
|
enum TCustom {
|
|
|
- Create {
|
|
|
- title: String,
|
|
|
- amount: isize,
|
|
|
- }
|
|
|
+ Create { title: String, amount: isize },
|
|
|
}
|
|
|
|
|
|
#[derive(Debug)]
|
|
@@ -234,10 +258,20 @@ mod tests {
|
|
|
type Context = ();
|
|
|
|
|
|
type CustomCommand = TCustom;
|
|
|
- fn run_custom(_ctx: &Self::Context, cmd: Self::CustomCommand, _query_ctx: impl Queryable<EntityOutput = Self::Entity>, insert_ctx: &impl Insertable<Self::Entity>) -> Result<(), Self::Error> {
|
|
|
+ fn run_custom(
|
|
|
+ _ctx: &Self::Context,
|
|
|
+ cmd: Self::CustomCommand,
|
|
|
+ _query_ctx: impl Queryable<EntityOutput = Self::Entity>,
|
|
|
+ insert_ctx: &impl Insertable<Self::Entity>,
|
|
|
+ ) -> Result<(), Self::Error> {
|
|
|
match cmd {
|
|
|
TCustom::Create { title, amount } => {
|
|
|
- insert_ctx.insert(Transaction { title, amount, customer: Default::default(), employee: Default::default() })?;
|
|
|
+ insert_ctx.insert(Transaction {
|
|
|
+ title,
|
|
|
+ amount,
|
|
|
+ customer: Default::default(),
|
|
|
+ employee: Default::default(),
|
|
|
+ })?;
|
|
|
},
|
|
|
}
|
|
|
Ok(())
|
|
@@ -292,10 +326,7 @@ mod tests {
|
|
|
.expect("couldn't count entries"),
|
|
|
0
|
|
|
);
|
|
|
- run_cmd(
|
|
|
- &db,
|
|
|
- &["execname", "customer", "create", "a_key"],
|
|
|
- );
|
|
|
+ run_cmd(&db, &["execname", "customer", "create", "a_key"]);
|
|
|
assert_eq!(
|
|
|
db.customers
|
|
|
.keyed("a_key")
|
|
@@ -303,10 +334,7 @@ mod tests {
|
|
|
.expect("couldn't count entries"),
|
|
|
1
|
|
|
);
|
|
|
- run_cmd(
|
|
|
- &db,
|
|
|
- &["execname", "customer", "delete", "a_key"],
|
|
|
- );
|
|
|
+ run_cmd(&db, &["execname", "customer", "delete", "a_key"]);
|
|
|
assert_eq!(
|
|
|
db.customers
|
|
|
.keyed("a_key")
|