aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-06-19 09:46:52 +0100
committerdiogo464 <[email protected]>2025-06-19 09:46:52 +0100
commit6a4e906586a043dff295be532d653f4635974502 (patch)
tree4248bbdb6d3791d37ef8df42abc698f021a3e835 /src
parent03793fad36480273ebd702e80f41f4baf513647c (diff)
Make --id a positional argument for improved CLI usability
- Remove --id flags from all command argument structures - Update RunArgs, StopArgs, TailArgs, CatArgs, StatusArgs to use positional ID - Update all integration tests to use new positional argument syntax - Update comprehensive LLM guide documentation with new command syntax - Maintain -- separator support for complex commands - More natural CLI interface: 'demon run web-server python -m http.server 8080' - Consistent with common tools like docker, systemctl, git - Breaking change but improves usability significantly - All tests pass with new CLI format Examples of new syntax: - demon run web-server python -m http.server 8080 - demon stop web-server - demon status web-server - demon tail web-server --stdout - demon cat web-server 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/main.rs71
1 files changed, 33 insertions, 38 deletions
diff --git a/src/main.rs b/src/main.rs
index 246af67..bedcb74 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -144,7 +144,6 @@ enum Commands {
144#[derive(Args)] 144#[derive(Args)]
145struct RunArgs { 145struct RunArgs {
146 /// Process identifier 146 /// Process identifier
147 #[arg(long)]
148 id: String, 147 id: String,
149 148
150 /// Command and arguments to execute 149 /// Command and arguments to execute
@@ -154,7 +153,6 @@ struct RunArgs {
154#[derive(Args)] 153#[derive(Args)]
155struct StopArgs { 154struct StopArgs {
156 /// Process identifier 155 /// Process identifier
157 #[arg(long)]
158 id: String, 156 id: String,
159 157
160 /// Timeout in seconds before sending SIGKILL after SIGTERM 158 /// Timeout in seconds before sending SIGKILL after SIGTERM
@@ -165,7 +163,6 @@ struct StopArgs {
165#[derive(Args)] 163#[derive(Args)]
166struct TailArgs { 164struct TailArgs {
167 /// Process identifier 165 /// Process identifier
168 #[arg(long)]
169 id: String, 166 id: String,
170 167
171 /// Only tail stdout 168 /// Only tail stdout
@@ -180,7 +177,6 @@ struct TailArgs {
180#[derive(Args)] 177#[derive(Args)]
181struct CatArgs { 178struct CatArgs {
182 /// Process identifier 179 /// Process identifier
183 #[arg(long)]
184 id: String, 180 id: String,
185 181
186 /// Only show stdout 182 /// Only show stdout
@@ -202,7 +198,6 @@ struct ListArgs {
202#[derive(Args)] 198#[derive(Args)]
203struct StatusArgs { 199struct StatusArgs {
204 /// Process identifier 200 /// Process identifier
205 #[arg(long)]
206 id: String, 201 id: String,
207} 202}
208 203
@@ -843,10 +838,10 @@ Demon is a command-line tool for spawning, managing, and monitoring background p
843 838
844## Available Commands 839## Available Commands
845 840
846### demon run --id <identifier> <command...> 841### demon run <identifier> <command...>
847Spawns a background process with the given identifier. 842Spawns a background process with the given identifier.
848 843
849**Syntax**: `demon run --id <id> [--] <command> [args...]` 844**Syntax**: `demon run <id> [--] <command> [args...]`
850 845
851**Behavior**: 846**Behavior**:
852- Creates `<id>.pid`, `<id>.stdout`, `<id>.stderr` files 847- Creates `<id>.pid`, `<id>.stdout`, `<id>.stderr` files
@@ -857,15 +852,15 @@ Spawns a background process with the given identifier.
857 852
858**Examples**: 853**Examples**:
859```bash 854```bash
860demon run --id web-server python -m http.server 8080 855demon run web-server python -m http.server 8080
861demon run --id backup-job -- rsync -av /data/ /backup/ 856demon run backup-job -- rsync -av /data/ /backup/
862demon run --id log-monitor tail -f /var/log/app.log 857demon run log-monitor tail -f /var/log/app.log
863``` 858```
864 859
865### demon stop --id <id> [--timeout <seconds>] 860### demon stop <id> [--timeout <seconds>]
866Stops a running daemon process gracefully. 861Stops a running daemon process gracefully.
867 862
868**Syntax**: `demon stop --id <id> [--timeout <seconds>]` 863**Syntax**: `demon stop <id> [--timeout <seconds>]`
869 864
870**Behavior**: 865**Behavior**:
871- Sends SIGTERM to the process first 866- Sends SIGTERM to the process first
@@ -876,8 +871,8 @@ Stops a running daemon process gracefully.
876 871
877**Examples**: 872**Examples**:
878```bash 873```bash
879demon stop --id web-server 874demon stop web-server
880demon stop --id backup-job --timeout 30 875demon stop backup-job --timeout 30
881``` 876```
882 877
883### demon list [--quiet] 878### demon list [--quiet]
@@ -903,10 +898,10 @@ backup-job:12346:DEAD
903- `RUNNING`: Process is actively running 898- `RUNNING`: Process is actively running
904- `DEAD`: Process has terminated, files still exist 899- `DEAD`: Process has terminated, files still exist
905 900
906### demon status --id <id> 901### demon status <id>
907Shows detailed status information for a specific daemon. 902Shows detailed status information for a specific daemon.
908 903
909**Syntax**: `demon status --id <id>` 904**Syntax**: `demon status <id>`
910 905
911**Output includes**: 906**Output includes**:
912- Daemon ID and PID file location 907- Daemon ID and PID file location
@@ -917,13 +912,13 @@ Shows detailed status information for a specific daemon.
917 912
918**Example**: 913**Example**:
919```bash 914```bash
920demon status --id web-server 915demon status web-server
921``` 916```
922 917
923### demon cat --id <id> [--stdout] [--stderr] 918### demon cat <id> [--stdout] [--stderr]
924Displays the contents of daemon log files. 919Displays the contents of daemon log files.
925 920
926**Syntax**: `demon cat --id <id> [--stdout] [--stderr]` 921**Syntax**: `demon cat <id> [--stdout] [--stderr]`
927 922
928**Behavior**: 923**Behavior**:
929- Shows both stdout and stderr by default 924- Shows both stdout and stderr by default
@@ -933,15 +928,15 @@ Displays the contents of daemon log files.
933 928
934**Examples**: 929**Examples**:
935```bash 930```bash
936demon cat --id web-server # Show both logs 931demon cat web-server # Show both logs
937demon cat --id web-server --stdout # Show only stdout 932demon cat web-server --stdout # Show only stdout
938demon cat --id web-server --stderr # Show only stderr 933demon cat web-server --stderr # Show only stderr
939``` 934```
940 935
941### demon tail --id <id> [--stdout] [--stderr] 936### demon tail <id> [--stdout] [--stderr]
942Follows daemon log files in real-time (like `tail -f`). 937Follows daemon log files in real-time (like `tail -f`).
943 938
944**Syntax**: `demon tail --id <id> [--stdout] [--stderr]` 939**Syntax**: `demon tail <id> [--stdout] [--stderr]`
945 940
946**Behavior**: 941**Behavior**:
947- Shows existing content first, then follows new content 942- Shows existing content first, then follows new content
@@ -952,8 +947,8 @@ Follows daemon log files in real-time (like `tail -f`).
952 947
953**Examples**: 948**Examples**:
954```bash 949```bash
955demon tail --id web-server # Follow both logs 950demon tail web-server # Follow both logs
956demon tail --id web-server --stdout # Follow only stdout 951demon tail web-server --stdout # Follow only stdout
957``` 952```
958 953
959### demon clean 954### demon clean
@@ -993,31 +988,31 @@ All files are created in the current working directory where `demon run` is exec
993 988
994### Starting a Web Server 989### Starting a Web Server
995```bash 990```bash
996demon run --id my-web-server python -m http.server 8080 991demon run my-web-server python -m http.server 8080
997demon status --id my-web-server # Check if it started 992demon status my-web-server # Check if it started
998demon tail --id my-web-server # Monitor logs 993demon tail my-web-server # Monitor logs
999``` 994```
1000 995
1001### Running a Backup Job 996### Running a Backup Job
1002```bash 997```bash
1003demon run --id nightly-backup -- rsync -av /data/ /backup/ 998demon run nightly-backup -- rsync -av /data/ /backup/
1004demon cat --id nightly-backup # Check output when done 999demon cat nightly-backup # Check output when done
1005demon clean # Clean up after completion 1000demon clean # Clean up after completion
1006``` 1001```
1007 1002
1008### Managing Multiple Services 1003### Managing Multiple Services
1009```bash 1004```bash
1010demon run --id api-server ./api --port 3000 1005demon run api-server ./api --port 3000
1011demon run --id worker-queue ./worker --config prod.conf 1006demon run worker-queue ./worker --config prod.conf
1012demon list # See all running services 1007demon list # See all running services
1013demon stop --id api-server # Stop specific service 1008demon stop api-server # Stop specific service
1014``` 1009```
1015 1010
1016### Monitoring and Debugging 1011### Monitoring and Debugging
1017```bash 1012```bash
1018demon list --quiet | grep RUNNING # Machine-readable active processes 1013demon list --quiet | grep RUNNING # Machine-readable active processes
1019demon tail --id problematic-app --stderr # Monitor just errors 1014demon tail problematic-app --stderr # Monitor just errors
1020demon status --id failing-service # Get detailed status 1015demon status failing-service # Get detailed status
1021``` 1016```
1022 1017
1023## Error Handling 1018## Error Handling
@@ -1040,12 +1035,12 @@ demon status --id failing-service # Get detailed status
1040### Scripting 1035### Scripting
1041```bash 1036```bash
1042# Check if service is running 1037# Check if service is running
1043if demon status --id my-service | grep -q "RUNNING"; then 1038if demon status my-service | grep -q "RUNNING"; then
1044 echo "Service is running" 1039 echo "Service is running"
1045fi 1040fi
1046 1041
1047# Start service if not running 1042# Start service if not running
1048demon list --quiet | grep -q "my-service:" || demon run --id my-service ./my-app 1043demon list --quiet | grep -q "my-service:" || demon run my-service ./my-app
1049 1044
1050# Get machine-readable process list 1045# Get machine-readable process list
1051demon list --quiet > process_status.txt 1046demon list --quiet > process_status.txt