atareao bu gisti düzenledi 1 month ago. Düzenlemeye git
1 file changed, 86 insertions
cli.rs(dosya oluşturuldu)
| @@ -0,0 +1,86 @@ | |||
| 1 | + | use clap::{Parser, Subcommand}; | |
| 2 | + | ||
| 3 | + | /// Suite de herramientas CLI para sysadmins | |
| 4 | + | /// | |
| 5 | + | /// crustaceo-tools unifica en un solo binario todas las herramientas | |
| 6 | + | /// que has ido construyendo: estadisticas de archivo, parseo de logs, | |
| 7 | + | /// informacion del sistema, grep recursivo y dashboard en terminal. | |
| 8 | + | /// | |
| 9 | + | /// Ejemplos: | |
| 10 | + | /// crustaceo-tools stats archivo.log | |
| 11 | + | /// crustaceo-tools logparse --level error archivo.log | |
| 12 | + | /// crustaceo-tools sysinfo | |
| 13 | + | /// crustaceo-tools grep "ERROR" /var/log/ | |
| 14 | + | /// crustaceo-tools dashboard --watch | |
| 15 | + | /// crustaceo-tools completions --shell bash | |
| 16 | + | #[derive(Parser)] | |
| 17 | + | #[command( | |
| 18 | + | name = "crustaceo-tools", | |
| 19 | + | version = "0.1.0", | |
| 20 | + | author = "Tu Nombre <tu@email.com>", | |
| 21 | + | about = "Suite de herramientas CLI para sysadmins", | |
| 22 | + | long_about = None, | |
| 23 | + | subcommand_negates_reqs = true | |
| 24 | + | )] | |
| 25 | + | pub struct Cli { | |
| 26 | + | #[command(subcommand)] | |
| 27 | + | pub comando: Comandos, | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | /// Subcomandos disponibles en crustaceo-tools | |
| 31 | + | #[derive(Subcommand)] | |
| 32 | + | pub enum Comandos { | |
| 33 | + | /// Estadisticas basicas de un archivo (lineas, palabras, caracteres) | |
| 34 | + | Stats { | |
| 35 | + | /// Ruta al archivo a analizar | |
| 36 | + | archivo: String, | |
| 37 | + | }, | |
| 38 | + | ||
| 39 | + | /// Parsea un archivo de logs y filtra por nivel | |
| 40 | + | Logparse { | |
| 41 | + | /// Nivel de log a filtrar (error, warn, info, debug) | |
| 42 | + | #[arg(short = 'l', long = "level", default_value = "info")] | |
| 43 | + | nivel: String, | |
| 44 | + | ||
| 45 | + | /// Mostrar solo las lineas que coinciden, sin metadatos | |
| 46 | + | #[arg(short = 'q', long = "quiet")] | |
| 47 | + | quiet: bool, | |
| 48 | + | ||
| 49 | + | /// Archivo de log a procesar | |
| 50 | + | archivo: String, | |
| 51 | + | }, | |
| 52 | + | ||
| 53 | + | /// Muestra informacion del sistema (CPU, memoria, disco) | |
| 54 | + | Sysinfo { | |
| 55 | + | /// Formato de salida (texto o json) | |
| 56 | + | #[arg(short = 'f', long = "format", default_value = "text", value_parser = ["text", "json"])] | |
| 57 | + | formato: String, | |
| 58 | + | }, | |
| 59 | + | ||
| 60 | + | /// Busca un patron en archivos (grep recursivo con regex) | |
| 61 | + | Grep { | |
| 62 | + | /// Patron de busqueda (expresion regular) | |
| 63 | + | patron: String, | |
| 64 | + | ||
| 65 | + | /// Ignorar mayusculas/minusculas | |
| 66 | + | #[arg(short = 'i', long = "ignore-case")] | |
| 67 | + | ignorar_mayusculas: bool, | |
| 68 | + | ||
| 69 | + | /// Archivo(s) o directorio(s) donde buscar | |
| 70 | + | archivo: String, | |
| 71 | + | }, | |
| 72 | + | ||
| 73 | + | /// Muestra un dashboard del sistema en tiempo real | |
| 74 | + | Dashboard { | |
| 75 | + | /// Actualizar cada N segundos automaticamente | |
| 76 | + | #[arg(short = 'w', long = "watch", default_value = "0")] | |
| 77 | + | watch: u64, | |
| 78 | + | }, | |
| 79 | + | ||
| 80 | + | /// Genera scripts de autocompletado para shells | |
| 81 | + | Completions { | |
| 82 | + | /// Shell para la que generar el autocompletado | |
| 83 | + | #[arg(short = 's', long = "shell", value_parser = ["bash", "zsh", "fish"])] | |
| 84 | + | shell: String, | |
| 85 | + | }, | |
| 86 | + | } | |
Daha yeni
Daha eski