From fdcb10c076afa49c53329b2617eea43e24dd1156 Mon Sep 17 00:00:00 2001 From: liutong Date: Tue, 13 Jun 2023 22:35:11 +0800 Subject: [PATCH] refactor: add rust framework for builtins. --- bash-5.1/.gitignore | 4 ++++ bash-5.1/Cargo.lock | 19 +++++++++++++++++++ bash-5.1/Cargo.toml | 12 ++++++++++++ bash-5.1/builtins/command1/Cargo.toml | 8 ++++++++ bash-5.1/builtins/command1/src/lib.rs | 12 ++++++++++++ bash-5.1/builtins/command2/Cargo.toml | 8 ++++++++ bash-5.1/builtins/command2/src/lib.rs | 11 +++++++++++ bash-5.1/src/main.rs | 10 ++++++++++ record.txt | 1 + 9 files changed, 85 insertions(+) create mode 100644 bash-5.1/.gitignore create mode 100644 bash-5.1/Cargo.lock create mode 100644 bash-5.1/Cargo.toml create mode 100644 bash-5.1/builtins/command1/Cargo.toml create mode 100644 bash-5.1/builtins/command1/src/lib.rs create mode 100644 bash-5.1/builtins/command2/Cargo.toml create mode 100644 bash-5.1/builtins/command2/src/lib.rs create mode 100644 bash-5.1/src/main.rs diff --git a/bash-5.1/.gitignore b/bash-5.1/.gitignore new file mode 100644 index 00000000..6c7dbc5f --- /dev/null +++ b/bash-5.1/.gitignore @@ -0,0 +1,4 @@ +*.swp +tags +target/ +.vscode diff --git a/bash-5.1/Cargo.lock b/bash-5.1/Cargo.lock new file mode 100644 index 00000000..80e89c60 --- /dev/null +++ b/bash-5.1/Cargo.lock @@ -0,0 +1,19 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "command1" +version = "0.1.0" + +[[package]] +name = "command2" +version = "0.1.0" + +[[package]] +name = "rsbash" +version = "0.1.0" +dependencies = [ + "command1", + "command2", +] diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml new file mode 100644 index 00000000..ec2f4f94 --- /dev/null +++ b/bash-5.1/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "rsbash" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = ["builtins/command1", "builtins/command2"] + +[dependencies] +command1 = {path = "./builtins/command1"} +command2 = {path = "./builtins/command2"} diff --git a/bash-5.1/builtins/command1/Cargo.toml b/bash-5.1/builtins/command1/Cargo.toml new file mode 100644 index 00000000..97f99352 --- /dev/null +++ b/bash-5.1/builtins/command1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "command1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/bash-5.1/builtins/command1/src/lib.rs b/bash-5.1/builtins/command1/src/lib.rs new file mode 100644 index 00000000..4655c221 --- /dev/null +++ b/bash-5.1/builtins/command1/src/lib.rs @@ -0,0 +1,12 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} + + pub fn say_hello() { + println!("hello 1111!"); + } diff --git a/bash-5.1/builtins/command2/Cargo.toml b/bash-5.1/builtins/command2/Cargo.toml new file mode 100644 index 00000000..c32d68c9 --- /dev/null +++ b/bash-5.1/builtins/command2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "command2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/bash-5.1/builtins/command2/src/lib.rs b/bash-5.1/builtins/command2/src/lib.rs new file mode 100644 index 00000000..a31d1d73 --- /dev/null +++ b/bash-5.1/builtins/command2/src/lib.rs @@ -0,0 +1,11 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} +pub fn hello2() { + println!("222222222222222"); +} diff --git a/bash-5.1/src/main.rs b/bash-5.1/src/main.rs new file mode 100644 index 00000000..b1ec861f --- /dev/null +++ b/bash-5.1/src/main.rs @@ -0,0 +1,10 @@ +use command1::say_hello; +use command2::hello2; + + +fn main() { + hello2(); + say_hello(); + println!("Hello, world!"); + //execute_cmd(); +} diff --git a/record.txt b/record.txt index 099b7d91..a4265686 100644 --- a/record.txt +++ b/record.txt @@ -2,3 +2,4 @@ 2 1 2 +3 -- Gitee