Skip to content
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

✨ Add cli based text generator #1

Merged
merged 9 commits into from
May 5, 2024
26 changes: 26 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Rust

on:
push:
branches: ['**']
paths:
- .github/workflows/rust.yml
- '**/*.rs'
- Cargo.toml
- Cargo.lock
pull_request:
branches: ['master']

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
!Cargo.toml
!Cargo.lock

# give github related files a free pass
!/.github/**/*

# ... not when they are in subdirectories
!*/
282 changes: 282 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
fastrand = "2.1.0"

[dev-dependencies]
regex = "1.10.4"
28 changes: 28 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[derive(clap::Parser)]
#[clap(version, about)]
pub struct Command {
#[command(subcommand)]
pub subcmd: SubCommand,
}

#[derive(clap::Subcommand)]
pub enum SubCommand {
#[command(subcommand, aliases=["gen"])]
Generate(GenerateCmd),
}

#[derive(clap::Subcommand)]
pub enum GenerateCmd {
Text {
#[clap(long, short, default_value = ".")]
path: String,
#[clap(long, default_value_t = false)]
to_stdout: bool,
#[clap(long, default_value_t = false)]
to_stderr: bool,
#[clap(long, short, default_value_t = 1024)]
size: u128,
#[clap(long, short, default_value_t = 1)]
count: u64,
},
}
7 changes: 7 additions & 0 deletions src/generator/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod text;

use std::io;

pub trait Generator {
fn generate(&self, out: impl io::Write);
}
Loading