-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(helper): add more external help providers to plz menu #56
Conversation
PR looks good! I think we can follow an approach like this for avoiding code duplication: (rough sketch) trait InfoProvider {
// Return the URL of the cheat sheet provider.
fn url(&self) -> &str;
// Show the cheat sheet for the given command.
fn show_info<Output: Write>(
&self,
cmd: &str,
pager: &Option<String>,
output: &mut Output,
) -> Result<()> {
let client = AgentBuilder::new().build();
let cheat_sheet = client
.get(&format!("{}/{}", self.url(), cmd))
.call()
.map_err(|e| Error::from(Box::new(e)))?
.into_string()?;
// Don't use a pager when the topic is not found.
if let Some(pager) = pager
.as_ref()
.filter(|_| !cheat_sheet.starts_with("Unknown topic."))
{
let mut process = if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", pager])
.stdin(Stdio::piped())
.spawn()
} else {
Command::new("sh")
.args(["-c", pager])
.stdin(Stdio::piped())
.spawn()
}?;
if let Some(stdin) = process.stdin.as_mut() {
writeln!(stdin, "{}", cheat_sheet)?;
process.wait()?;
}
} else {
writeln!(output, "{}", cheat_sheet)?;
}
Ok(())
}
}
struct CheatSh {}
impl InfoProvider for CheatSh {
fn url(&self) -> &str {
"https://cheat.sh"
}
}
struct EgPages {}
impl InfoProvider for EgPages {
fn url(&self) -> &str {
"https://raw.githubusercontent.com/srsudar/eg/master/eg/examples"
}
} |
It pretty reasonable approach |
# Conflicts: # src/helper/docs/mod.rs
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #56 +/- ##
==========================================
- Coverage 77.16% 75.76% -1.39%
==========================================
Files 14 16 +2
Lines 604 693 +89
==========================================
+ Hits 466 525 +59
- Misses 138 168 +30
☔ View full report in Codecov by Sentry. |
Hey @0x61nas, is this still on your list? |
yes, I'll try to make progress in this PR as soon as I can |
Alright, let's have this one ready for the next release! |
# Conflicts: # src/helper/docs/mod.rs
The 'cheat' module was renamed to 'cheat_sh'. The import statement in 'config.rs' is updated to reflect this new name. This change ensures the consistency in module naming and prevents import errors.
The error handling function `err_handle` in the `docs` module was refactored. Instead of simply returning a `Result<String>`, the function now returns an `Error` with two branches. The first branch handles the case where the error is of type `ureq::ErrorKind::HTTP`, returning a custom `ProviderError`. The second branch simply constructs an `Error` from the original error. This change provides more flexibility in handling different types of errors, increasing code robustness.
Changed the 'cheat_sh_url' in the config from a mandatory String to an optional String type. This will allow users to decide whether they want to provide a custom URL for cheat.sh or not, increasing flexibility in configuration options.
…to the `_fetch` function for better custom URL handling
…der trait for it
Hi @orhun, I created the initial form for the but I wanna make sure that the and sorry for the delay. |
Looks good, let's proceed with the implementation! 🐻
Not an issue! |
Feat/add chatsheets provider
Let me know when this is ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is now squashed and merged in adadc2e
Description
Add eg, cheat,
and Command Line Interface Pagesas options to the plz menuI actually added eg only, 'cause it's obvious that we need a uniform way to handle all these options +cheat.sh
to reduce the code duplication, but I opened the PR anyway to track the progress and discuss the changes.Motivation and Context
How Has This Been Tested?
cargo t
plz
menuTypes of Changes
Checklist: