diff options
| author | diogo464 <[email protected]> | 2025-06-19 09:46:52 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-06-19 09:46:52 +0100 |
| commit | 6a4e906586a043dff295be532d653f4635974502 (patch) | |
| tree | 4248bbdb6d3791d37ef8df42abc698f021a3e835 /src/main.rs | |
| parent | 03793fad36480273ebd702e80f41f4baf513647c (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/main.rs')
| -rw-r--r-- | src/main.rs | 71 |
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)] |
| 145 | struct RunArgs { | 145 | struct 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)] |
| 155 | struct StopArgs { | 154 | struct 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)] |
| 166 | struct TailArgs { | 164 | struct 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)] |
| 181 | struct CatArgs { | 178 | struct 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)] |
| 203 | struct StatusArgs { | 199 | struct 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...> |
| 847 | Spawns a background process with the given identifier. | 842 | Spawns 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 |
| 860 | demon run --id web-server python -m http.server 8080 | 855 | demon run web-server python -m http.server 8080 |
| 861 | demon run --id backup-job -- rsync -av /data/ /backup/ | 856 | demon run backup-job -- rsync -av /data/ /backup/ |
| 862 | demon run --id log-monitor tail -f /var/log/app.log | 857 | demon 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>] |
| 866 | Stops a running daemon process gracefully. | 861 | Stops 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 |
| 879 | demon stop --id web-server | 874 | demon stop web-server |
| 880 | demon stop --id backup-job --timeout 30 | 875 | demon 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> |
| 907 | Shows detailed status information for a specific daemon. | 902 | Shows 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 |
| 920 | demon status --id web-server | 915 | demon status web-server |
| 921 | ``` | 916 | ``` |
| 922 | 917 | ||
| 923 | ### demon cat --id <id> [--stdout] [--stderr] | 918 | ### demon cat <id> [--stdout] [--stderr] |
| 924 | Displays the contents of daemon log files. | 919 | Displays 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 |
| 936 | demon cat --id web-server # Show both logs | 931 | demon cat web-server # Show both logs |
| 937 | demon cat --id web-server --stdout # Show only stdout | 932 | demon cat web-server --stdout # Show only stdout |
| 938 | demon cat --id web-server --stderr # Show only stderr | 933 | demon cat web-server --stderr # Show only stderr |
| 939 | ``` | 934 | ``` |
| 940 | 935 | ||
| 941 | ### demon tail --id <id> [--stdout] [--stderr] | 936 | ### demon tail <id> [--stdout] [--stderr] |
| 942 | Follows daemon log files in real-time (like `tail -f`). | 937 | Follows 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 |
| 955 | demon tail --id web-server # Follow both logs | 950 | demon tail web-server # Follow both logs |
| 956 | demon tail --id web-server --stdout # Follow only stdout | 951 | demon 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 |
| 996 | demon run --id my-web-server python -m http.server 8080 | 991 | demon run my-web-server python -m http.server 8080 |
| 997 | demon status --id my-web-server # Check if it started | 992 | demon status my-web-server # Check if it started |
| 998 | demon tail --id my-web-server # Monitor logs | 993 | demon tail my-web-server # Monitor logs |
| 999 | ``` | 994 | ``` |
| 1000 | 995 | ||
| 1001 | ### Running a Backup Job | 996 | ### Running a Backup Job |
| 1002 | ```bash | 997 | ```bash |
| 1003 | demon run --id nightly-backup -- rsync -av /data/ /backup/ | 998 | demon run nightly-backup -- rsync -av /data/ /backup/ |
| 1004 | demon cat --id nightly-backup # Check output when done | 999 | demon cat nightly-backup # Check output when done |
| 1005 | demon clean # Clean up after completion | 1000 | demon clean # Clean up after completion |
| 1006 | ``` | 1001 | ``` |
| 1007 | 1002 | ||
| 1008 | ### Managing Multiple Services | 1003 | ### Managing Multiple Services |
| 1009 | ```bash | 1004 | ```bash |
| 1010 | demon run --id api-server ./api --port 3000 | 1005 | demon run api-server ./api --port 3000 |
| 1011 | demon run --id worker-queue ./worker --config prod.conf | 1006 | demon run worker-queue ./worker --config prod.conf |
| 1012 | demon list # See all running services | 1007 | demon list # See all running services |
| 1013 | demon stop --id api-server # Stop specific service | 1008 | demon stop api-server # Stop specific service |
| 1014 | ``` | 1009 | ``` |
| 1015 | 1010 | ||
| 1016 | ### Monitoring and Debugging | 1011 | ### Monitoring and Debugging |
| 1017 | ```bash | 1012 | ```bash |
| 1018 | demon list --quiet | grep RUNNING # Machine-readable active processes | 1013 | demon list --quiet | grep RUNNING # Machine-readable active processes |
| 1019 | demon tail --id problematic-app --stderr # Monitor just errors | 1014 | demon tail problematic-app --stderr # Monitor just errors |
| 1020 | demon status --id failing-service # Get detailed status | 1015 | demon 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 |
| 1043 | if demon status --id my-service | grep -q "RUNNING"; then | 1038 | if demon status my-service | grep -q "RUNNING"; then |
| 1044 | echo "Service is running" | 1039 | echo "Service is running" |
| 1045 | fi | 1040 | fi |
| 1046 | 1041 | ||
| 1047 | # Start service if not running | 1042 | # Start service if not running |
| 1048 | demon list --quiet | grep -q "my-service:" || demon run --id my-service ./my-app | 1043 | demon 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 |
| 1051 | demon list --quiet > process_status.txt | 1046 | demon list --quiet > process_status.txt |
