Skip to content

Commit 6c9d5c8

Browse files
committed
added command line args
1 parent a48cf9a commit 6c9d5c8

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cargo clippy
104104
cargo fmt --check
105105

106106
# rust-analyzer can analyze the project
107-
rust-analyzer analysis-stats /path/to/zero2prod
107+
rust-analyzer analysis-stats .
108108
```
109109

110110
From inside Vim:
@@ -128,6 +128,7 @@ From inside Vim:
128128
| `[d` / `]d` | Previous / next diagnostic |
129129
| `<leader>d` | Show current diagnostic |
130130
| `:LspDiagShow` | Open quickfix list with all diagnostics |
131+
| `:LspDiagCurrent` | Get info on the highlighted error |
131132

132133
## Hello, World! Why Rust?
133134

‎src/main.rs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
use std::env;
2+
use std::str::FromStr;
3+
14
fn main() {
2-
println!("Hello, world!");
3-
println!("-3 to the power of 2 is:");
4-
println!("{}", power(-3, 2));
5+
println!("Hello, maths powers!");
6+
7+
let mut numbers = Vec::new();
8+
for arg in env::args().skip(1) {
9+
numbers.push(i64::from_str(&arg).expect("error parsing arg"));
10+
}
11+
12+
if numbers.is_empty() {
13+
eprintln!("Usage: powers NUMBER EXP");
14+
std::process::exit(1);
15+
}
16+
if numbers.len() > 2 {
17+
eprintln!("Usage: powers NUMBER EXP");
18+
eprintln!("Error: only two values expected saw {}", numbers.len());
19+
std::process::exit(1);
20+
}
21+
22+
println!("{}", power(numbers[0], numbers[1]));
523
}
624

725
fn power(base: i64, n: i64) -> i64 {

0 commit comments

Comments
 (0)