Updated CONTRIBUTING.md

This commit is contained in:
Nathan Fisher 2023-01-06 23:53:41 -05:00
parent fb389fd309
commit e3071e5707

View File

@ -17,8 +17,8 @@ in snake case. This struct must implement `Cmd`. It is recommended that this str
have at least the fields `name: &'static str` and `path: crate::Path`. The have at least the fields `name: &'static str` and `path: crate::Path`. The
trait methods `name` and `path` can then just return the corresponding fields. trait methods `name` and `path` can then just return the corresponding fields.
The applet module should further contain a constant which is basically the The applet module should further implement `Default` for the struct which implements
default instance for this struct. the `Cmd` trait.
## A Simple Example Applet ## A Simple Example Applet
```Rust ```Rust
@ -26,15 +26,20 @@ default instance for this struct.
use clap::Command; use clap::Command;
use super::Cmd; use super::Cmd;
#[derive(Debug)]
pub struct MyApplet { pub struct MyApplet {
name: &'static str, name: &'static str,
path: crate::Path, path: crate::Path,
} }
pub const MYAPPLET: MyApplet = MyApplet { impl Default for MyApplet {
name: "myapplet", fn default() -> Self {
path: crate::Path::UsrBin, Self {
}; name: "myapplet",
path: Some(crate::Path::UseBin),
}
}
}
impl Cmd for MyApplet { impl Cmd for MyApplet {
fn name(&self) -> &str { fn name(&self) -> &str {
@ -60,18 +65,9 @@ impl Cmd for MyApplet {
``` ```
## Incorporating a new applet ## Incorporating a new applet
Each command module should be public in `src/cmd/mod.rs` and both the struct which Each command module should be public in `src/cmd/mod.rs` and both the struct which
implements `Cmd` and the constant which is an instance of that struct should be implements `Cmd` should be exported as public in that file. The function `cmd::get`
exported as public in that file. has a match statement, to which should be added a line which matches the name of
the new command and returns an `Option<Box<dyn Cmd>>` for your type. The static
There are several other files which must also be edited to fully integrate a new `cmd::COMMANDS` should have your new command's name added and the array's number
command. Expect improvements to this process as the Api evolves. incremented by 1.
- src/lib.rs: The function `run` has a match statement which checks the name with
which the program was invoked. A new match arm must be added here.
- src/cmd/bootstrap/mod.rs: The `run` method has a `Vec` of trait objects representing
all of the available applets. The constant which is an instance of the struct implementing
`Cmd` should be added to this `Vec`.
-src/cmd/shitbox/mod.rs: The `cli` method will need `MYAPPLET.cli()` added in to
the `clap` subcommands. The `run` method has a match statement which checks the
subcommand that has been asked to run. A new match arm must also be added here.