Misunderstanding Jump from 1.4->1.5+
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 122
- Avg merge
- 10h 37m
- Merged PRs (30d)
- 2
Description
First, thank you for taking the time to create this guide (and reading this). :-)
It was my understanding from the beginning that the guide would guide one towards creating a simple Command Line App, but after 1.4 there doesn't appear to be much cohesion. I assume I am missing something here, but 1.5 (and further) changes main.rs in a way that it doesn't appear to function around the same logic built/defined before 1.4.
#![allow(unused)]
use clap::Parser;
/// Search for a pattern in a file and display the lines that contain it.
#[derive(Parser)]
struct Cli {
/// The pattern to look for
pattern: String,
/// The path to the file to read
path: std::path::PathBuf,
}
fn main() {
let args = Cli::parse();
let content = std::fs::read_to_string(&args.path).expect("could not read file");
for line in content.lines() {
if line.contains(&args.pattern) {
println!("{}", line);
}
}
}
use anyhow::{Context, Result};
fn main() -> Result<()> {
let path = "test.txt";
let content = std::fs::read_to_string(path)
.with_context(|| format!("could not read file `{}`", path))?;
println!("file content: {}", content);
Ok(())
}
1.5 gives an example of a bunch of nice tools to add (such as logging and progress bars), but as mentioned earlier, there is no cohesion with the early development; no addition to the previously constructed chapters.
Printer Performance
#![allow(unused)]
fn main() {
use std::io::{self, Write};
let stdout = io::stdout(); // get the global stdout entity
let mut handle = stdout.lock(); // acquire a lock on it
writeln!(handle, "foo: {}", 42); // add `?` if you care about errors here
}
Progress Bar
fn main() {
let pb = indicatif::ProgressBar::new(100);
for i in 0..100 {
do_hard_work();
pb.println(format!("[+] finished #{}", i));
pb.inc(1);
}
pb.finish_with_message("done");
}
Logging
use log::{info, warn};
fn main() {
env_logger::init();
info!("starting up");
warn!("oops, nothing implemented!");
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked tutorial chapters 1.3, 1.4, and 1.5, comparing how main.rs and the command-line example evolve between them. Determine the intended progression and update the tutorial so the later output, logging, and progress-bar material connects coherently to the earlier application; the chapters should form a clear continuous guide when done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100