97 points · by csomar · 5y ago · 48 comments
It would be better to just go look at real CLI utilities and see what they do instead of trying to use something like this IMO. This project seems to just be throwing everything against the wall. It's likely you won't need most of it. For example, this template uses twice as many dependencies as ripgrep.
Rust is quite feature rich and perfectly usable without any of these.
Some people are a bit trigger happy when adding dependencies, without considering the extra cost in maintenance and security.
There may be alternatives, but a new person might be wondering "how do I generate a random number in Rust" and not want to roll their own RNG or find another library.
And that's not to say you have to use any of those in any particular project, just that they are the main options for achieving their particular functionality.
The fact that there isn't a framework doesn't mean there's a problem. It could just be you have an unnatural need for structure where none is needed.
https://github.com/nemesiscodex/actix-todo
My advice is pick a http server that you want to use and search github for Cargo.lock
The extensions all have a lot of boilerplate so we use it as a replacement for a PHONY make target for niceties for the extension author like question prompts, enumerated lists for selecting, etc.
[EDIT: Also snafu, hello there Shepmaster :P ]
It works well for libraries and applications and has bells and whistles you might want, such as backtrace captures on stable Rust.
See https://rust-starter.github.io/#feature-errors for why Failure is still used.
1. Is there an example application that uses the starter?
2. Does it follow the command line interface guidelines at https://clig.dev?
2. First time I this. There are things that relate to Clap and things (like configuration) that could be implemented in rust-starter.
[0] https://github.com/joyent/statemap/blob/rust/src/main.rs#L95
What clap gives you is something more like Python's argparse, which offers things like convenient parsing, automatically generated manpages and error/usage messages, etc.
https://github.com/ablakey/gameboy/blob/master/src/main.rs#L...
(I'm sure people will shout that this isn't the right way to parse optional flags)
Since that sounds like a challenge, just wanted to make sure that people are aware of Iterator::nth (https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...), which means you can entirely replace lines 8 and 9 with `let cartridge_path = env::args().nth(1);` :) In combination with Iterator::any to replace line 10, you can avoid a whopping five whole heap allocations this way!! :P
I feel like when I'm done I need to find a bit of cash and get a veteran to code review the whole thing. I'm learning a ton by suffering through it myself. But also probably missing a lot of great shortcuts and tips.
I assume the "five heap allocations" is kinda tongue in cheek? My understanding is that while it is good to avoid heap allocations, given this is a called-once piece of code, it's not really a big deal?
With Rust you will soon see that most applications require some sort of dependency like serde for serialization, etc.
#[derive(StructOpt)]
struct Opt {
#[structopt(short, long)]
debug: bool,
#[structopt(short = "c", long)]
nb_cars: Option<i32>,
#[structopt(short, long)]
level: Vec<String>,
}26. Show HN: Rust-starter, a boilerplate to build Rust CLI applications (github.com/rust-starter) 18 points by csomar 19 minutes ago | flag | hide | past | 6 comments
27. Finland has slashed homelessness; the rest of Europe is failing (economist.com) 30 points by ashergill 19 minutes ago | flag | hide | past | 11 comments
28. The Reasons I’m Joining BIGtoken as CEO (medium.com/crypto-oracle) 3 points by simonebrunozzi 19 minutes ago | flag | hide | past | 1 comment
29. Upvote to encourage more people to visit New Links on Hacker News (ycombinator.com) 164 points by crazypython 21 minutes ago | hide | past | 19 comments