initial commit
This commit is contained in:
commit
99ebda0e56
17 changed files with 2162 additions and 0 deletions
39
'
Normal file
39
'
Normal file
|
@ -0,0 +1,39 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::process;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
let config = Config::build(&args).unwrap_or_else(|err| {
|
||||
println!("Problem parsing arguments: {err}");
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
run(config);
|
||||
}
|
||||
|
||||
fn run(config: Config) -> Result<(), Box<dyn Error>> {
|
||||
let contents =
|
||||
fs::read_to_string(config.file_path).expect("Should have have been able to read the file!");
|
||||
|
||||
println!("With text:\n{contents}");
|
||||
}
|
||||
|
||||
struct Config {
|
||||
query: String,
|
||||
file_path: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn build(args: &[String]) -> Result<Config, &'static str> {
|
||||
if args.len() < 3 {
|
||||
return Err("not enough arguments!");
|
||||
}
|
||||
|
||||
let query = args[1].clone();
|
||||
let file_path = args[2].clone();
|
||||
|
||||
Ok(Config { query, file_path })
|
||||
}
|
||||
}
|
19
.direnv/bin/nix-direnv-reload
Executable file
19
.direnv/bin/nix-direnv-reload
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ ! -d "/home/youwen/Source/active/minigrep" ]]; then
|
||||
echo "Cannot find source directory; Did you move it?"
|
||||
echo "(Looking for "/home/youwen/Source/active/minigrep")"
|
||||
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# rebuild the cache forcefully
|
||||
_nix_direnv_force_reload=1 direnv exec "/home/youwen/Source/active/minigrep" true
|
||||
|
||||
# Update the mtime for .envrc.
|
||||
# This will cause direnv to reload again - but without re-building.
|
||||
touch "/home/youwen/Source/active/minigrep/.envrc"
|
||||
|
||||
# Also update the timestamp of whatever profile_rc we have.
|
||||
# This makes sure that we know we are up to date.
|
||||
touch -r "/home/youwen/Source/active/minigrep/.envrc" "/home/youwen/Source/active/minigrep/.direnv"/*.rc
|
1
.direnv/flake-inputs/0zm67d16ijif01c3fzcng4lhazz3b08i-source
Symbolic link
1
.direnv/flake-inputs/0zm67d16ijif01c3fzcng4lhazz3b08i-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/0zm67d16ijif01c3fzcng4lhazz3b08i-source
|
1
.direnv/flake-inputs/byd6aqsq9m8kk6wwvz3dgdd1114bqmbb-source
Symbolic link
1
.direnv/flake-inputs/byd6aqsq9m8kk6wwvz3dgdd1114bqmbb-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/byd6aqsq9m8kk6wwvz3dgdd1114bqmbb-source
|
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
|
1
.direnv/flake-inputs/sfycwi72zfjsspidinx56ajaiffpyh17-source
Symbolic link
1
.direnv/flake-inputs/sfycwi72zfjsspidinx56ajaiffpyh17-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/sfycwi72zfjsspidinx56ajaiffpyh17-source
|
1
.direnv/flake-inputs/v9dvfkr6rpl1dh02b4lyjx0gzwkiwvk3-source
Symbolic link
1
.direnv/flake-inputs/v9dvfkr6rpl1dh02b4lyjx0gzwkiwvk3-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/v9dvfkr6rpl1dh02b4lyjx0gzwkiwvk3-source
|
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
|
1
.direnv/flake-profile-79bc5a9415c131a89d82b091c16b36e06e395e8f
Symbolic link
1
.direnv/flake-profile-79bc5a9415c131a89d82b091c16b36e06e395e8f
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/hg9ymxmrlw6csbbppwhbr552icsy375x-nix-shell-env
|
2024
.direnv/flake-profile-79bc5a9415c131a89d82b091c16b36e06e395e8f.rc
Normal file
2024
.direnv/flake-profile-79bc5a9415c131a89d82b091c16b36e06e395e8f.rc
Normal file
File diff suppressed because it is too large
Load diff
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake github:youwen5/nix-dev-envs#rustStable
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "minigrep"
|
||||
version = "0.1.0"
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "minigrep"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
9
poem.txt
Normal file
9
poem.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
I'm nobody! Who are you?
|
||||
Are you nobody, too?
|
||||
Then there's a pair of us - don't tell!
|
||||
They'd banish us, you know.
|
||||
|
||||
How dreary to be somebody!
|
||||
How public, like a frog
|
||||
To tell your name the livelong day
|
||||
To an admiring bog!
|
28
src/lib.rs
Normal file
28
src/lib.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use std::error::Error;
|
||||
use std::fs;
|
||||
|
||||
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
|
||||
let contents = fs::read_to_string(config.file_path)?;
|
||||
|
||||
println!("With text:\n{contents}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Config {
|
||||
pub query: String,
|
||||
pub file_path: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn build(args: &[String]) -> Result<Config, &'static str> {
|
||||
if args.len() < 3 {
|
||||
return Err("not enough arguments!");
|
||||
}
|
||||
|
||||
let query = args[1].clone();
|
||||
let file_path = args[2].clone();
|
||||
|
||||
Ok(Config { query, file_path })
|
||||
}
|
||||
}
|
21
src/main.rs
Normal file
21
src/main.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::env;
|
||||
use std::process;
|
||||
|
||||
use minigrep::Config;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
let config = Config::build(&args).unwrap_or_else(|err| {
|
||||
println!("Problem parsing arguments: {err}");
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
println!("Searching for {}", config.query);
|
||||
println!("In file {}", config.file_path);
|
||||
|
||||
if let Err(e) = minigrep::run(config) {
|
||||
println!("Application error: {e}");
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue