https://github.com/linuxuser255/menu_run
A simple Rust application that presents an interactive menu and executes shell scripts based on user selection
https://github.com/linuxuser255/menu_run
Last synced: 8 days ago
JSON representation
A simple Rust application that presents an interactive menu and executes shell scripts based on user selection
- Host: GitHub
- URL: https://github.com/linuxuser255/menu_run
- Owner: LinuxUser255
- License: gpl-3.0
- Created: 2025-10-20T00:41:26.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-20T00:47:06.000Z (9 months ago)
- Last Synced: 2025-10-20T05:49:45.950Z (9 months ago)
- Language: Rust
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Menu Run
**A simple Rust application that presents an interactive menu and executes shell scripts based on user selection.**
## Execution Flow
When the program starts (`cargo run`), the following execution flow occurs:
```mermaid
flowchart TD
Start([Start main.rs]) --> Loop{Enter Loop}
Loop --> Prompt[Display Menu Prompt]
Prompt --> Input[Read User Input]
Input --> Parse[Convert to lowercase & trim]
Parse --> Match{Match Input}
Match -->|a| ScriptOne[Print shell script one]
Match -->|b| ScriptTwo[Print shell script two]
Match -->|c| ScriptThree[Print shell script three]
Match -->|q/quit/exit| Exit[Print Exiting...]
Match -->|Invalid| Invalid[Print Invalid selection]
ScriptOne --> RunOne["runner::run(Script::One)"]
ScriptTwo --> RunTwo["runner::run(Script::Two)"]
ScriptThree --> RunThree["runner::run(Script::Three)"]
RunOne --> ExecOne[Execute ./scripts/shell_script_one.sh]
RunTwo --> ExecTwo[Execute ./scripts/shell_script_two.sh]
RunThree --> ExecThree[Execute ./scripts/shell_script_three.sh]
ExecOne --> PrintCode1[Print exit code]
ExecTwo --> PrintCode2[Print exit code]
ExecThree --> PrintCode3[Print exit code]
PrintCode1 --> Break1[Break loop]
PrintCode2 --> Break2[Break loop]
PrintCode3 --> Break3[Break loop]
Exit --> Break4[Break loop]
Invalid --> Loop
Break1 --> End([End])
Break2 --> End
Break3 --> End
Break4 --> End
```
### Detailed Flow Description
1. **Program Start**: The `main()` function in `src/main.rs` begins execution.
2. **Interactive Loop**: The program enters an infinite loop that:
- Displays a menu prompt asking for user selection (A, B, C, or Q/quit/exit)
- Flushes stdout to ensure the prompt is immediately visible
3. **User Input Processing**:
- Reads a line from stdin
- Trims whitespace and converts to lowercase for case-insensitive matching
- If reading fails, displays an error and continues the loop
4. **Input Matching**:
- **Option A**: Prints "shell script one", calls `runner::run(Script::One)`, breaks loop
- **Option B**: Prints "shell script two", calls `runner::run(Script::Two)`, breaks loop
- **Option C**: Prints "shell script three", calls `runner::run(Script::Three)`, breaks loop
- **Quit (q/quit/exit)**: Prints "Exiting...", breaks loop
- **Invalid input**: Prints error message, continues loop
5. **Script Execution** (via `src/runner.rs`):
- The `run()` function receives a `Script` enum variant
- Maps the variant to corresponding script path:
- `Script::One` → `./scripts/shell_script_one.sh`
- `Script::Two` → `./scripts/shell_script_two.sh`
- `Script::Three` → `./scripts/shell_script_three.sh`
- Spawns a bash process with the script path as argument
- Captures and prints the exit code
- Returns the exit code wrapped in `Result`
6. **Program Termination**: After breaking the loop, prints a blank line and exits.
## Prerequisites
- Rust toolchain (edition 2024)
- Bash shell
- Execute permissions on shell scripts: `chmod +x scripts/*.sh`
## Usage
```bash
# Build the project
cargo build
# Run the application
cargo run
```