Skip to content

Commit 151f094

Browse files
authored
Update CONTRIBUTING.md
1 parent a7055f1 commit 151f094

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

CONTRIBUTING.md

+10-30
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,18 @@ Remarks:
107107

108108
Any package manager is supported, as long as there is a file you can get the dependencies from.
109109

110-
To add a new package manager, make sure you follow these steps:
111-
1. in `src/onefetch/deps/package_manager.rs`, add the name of your package manager to the `PackageManager` enum
112-
```rust
113-
pub enum PackageManager {
114-
// ...
115-
Cargo,
116-
// ...
117-
}
118-
```
110+
To add a new package manager, make sure to follow these steps:
119111

120-
2. in `src/onefetch/deps/package_manager.rs`, add a `writeln` macro call to the `fmt` function
121-
```rust
122-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
123-
match *self {
124-
// ...
125-
PackageManager::Cargo => write!(f, "cargo"),
126-
// ...
127-
}
128-
}
129-
```
112+
1. Add a new entry in the `define_package_managers!` macro in [package_manager.rs](https://raw.githubusercontent.com/o2sh/onefetch/master/src/deps/package_manager.rs).
113+
114+
**Example**:
115+
116+
`{ Cargo, "cargo", "Cargo.toml", cargo },`
117+
118+
The first item `Cargo` corresponds to the name of the package manager. The second item `cargo` is the display name. Then we have the name of the package manager file that will be parsed: `Cargo.toml`. The last item `cargo` corresponds to the function mame responsible for parsing the package manager file, cf. step 2.
119+
120+
2. in `src/onefetch/deps/package_parser.rs`, add a function that should take in a `string` as the content of the package manager file, and return `usize` as the number of dependencies.
130121

131-
3. in `src/onefetch/deps/package_parser.rs`, add a function whose name corresponds to your manager. This function should take in a `string` as the contents of the package manager file, and return `usize` as the number of dependencies. You should also make sure you catch any edge cases, such as the absence of a `dependencies` field.
132122
```rust
133123
pub fn cargo(contents: &str) -> Result<usize> {
134124
let parsed = contents.parse::<Value>()?;
@@ -141,16 +131,6 @@ pub fn cargo(contents: &str) -> Result<usize> {
141131
}
142132
```
143133

144-
4. in `src/onefetch/deps/mod.rs`, in the `new` method of the `DependencyDetector` impl, insert your new package managers information
145-
```rust
146-
package_managers.insert(
147-
String::from("Cargo.toml"), // File name
148-
149-
// Parser function, then the corresponding element from the PackageManager enum
150-
(package_parser::cargo, package_manager::PackageManager::Cargo),
151-
);
152-
```
153-
154134
### Adding translation for README.md
155135

156136
In order to make Onefetch more accessible for non English-speakers, we are seeking the help of multilingual contributors willing to translate the README.md in their native tongue.

0 commit comments

Comments
 (0)