summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@sequoia-pgp.org>2022-10-15 17:27:55 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2022-10-15 17:27:55 +0300
commited415b5fa1f0d1c85ab1cef5b8f5ee58951f9453 (patch)
treef26bb41b824d46fa461821151c266f5020718240
parentd441bbd44e9e3c96935059936b1cc8131a3405aa (diff)
downloadunixtool-ed415b5fa1f0d1c85ab1cef5b8f5ee58951f9453.tar.gz
refactor: prepare for many new subcommands
-rw-r--r--src/bin/unixtool.rs20
-rw-r--r--src/cmd/echo.rs (renamed from src/main.rs)24
-rw-r--r--src/cmd/mod.rs2
-rw-r--r--src/lib.rs1
4 files changed, 26 insertions, 21 deletions
diff --git a/src/bin/unixtool.rs b/src/bin/unixtool.rs
new file mode 100644
index 0000000..59feac1
--- /dev/null
+++ b/src/bin/unixtool.rs
@@ -0,0 +1,20 @@
+use clap::{Parser, Subcommand};
+use unixtool::cmd::Echo;
+
+fn main() {
+ let args = Args::parse();
+ match args.command {
+ Command::Echo(x) => x.run(),
+ }
+}
+
+#[derive(Parser)]
+struct Args {
+ #[clap(subcommand)]
+ command: Command,
+}
+
+#[derive(Subcommand)]
+enum Command {
+ Echo(Echo),
+}
diff --git a/src/main.rs b/src/cmd/echo.rs
index 13c9d34..fbe5f6d 100644
--- a/src/main.rs
+++ b/src/cmd/echo.rs
@@ -1,33 +1,15 @@
-use clap::{Parser, Subcommand};
-
-fn main() {
- let args = Args::parse();
- match args.command {
- Command::Echo(x) => x.run(),
- }
-}
-
-#[derive(Parser)]
-struct Args {
- #[clap(subcommand)]
- command: Command,
-}
-
-#[derive(Subcommand)]
-enum Command {
- Echo(Echo),
-}
+use clap::Parser;
/// Write the words given on the command line to stdout, then a
/// newline.
#[derive(Parser)]
-struct Echo {
+pub struct Echo {
/// Words to write out, if any.
words: Vec<String>,
}
impl Echo {
- fn run(&self) {
+ pub fn run(&self) {
let mut words = self.words.iter();
if let Some(word) = words.next() {
print!("{}", word);
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
new file mode 100644
index 0000000..d1744e5
--- /dev/null
+++ b/src/cmd/mod.rs
@@ -0,0 +1,2 @@
+mod echo;
+pub use echo::Echo;
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..52958ec
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1 @@
+pub mod cmd;