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
trait methods `name` and `path` can then just return the corresponding fields.
The applet module should further contain a constant which is basically the
default instance for this struct.
The applet module should further implement `Default` for the struct which implements
the `Cmd` trait.
## A Simple Example Applet
```Rust
@ -26,15 +26,20 @@ default instance for this struct.
use clap::Command;
use super::Cmd;
#[derive(Debug)]
pub struct MyApplet {
name: &'static str,
path: crate::Path,
}
pub const MYAPPLET: MyApplet = MyApplet {
name: "myapplet",
path: crate::Path::UsrBin,
};
impl Default for MyApplet {
fn default() -> Self {
Self {
name: "myapplet",
path: Some(crate::Path::UseBin),
}
}
}
impl Cmd for MyApplet {
fn name(&self) -> &str {
@ -60,18 +65,9 @@ impl Cmd for MyApplet {
```
## Incorporating a new applet
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
exported as public in that file.
There are several other files which must also be edited to fully integrate a new
command. Expect improvements to this process as the Api evolves.
- 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.
implements `Cmd` should be exported as public in that file. The function `cmd::get`
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
`cmd::COMMANDS` should have your new command's name added and the array's number
incremented by 1.