cmdx/
lib.rs

1//! # cmdx - Cross-Platform Command and Path Translator Library
2//!
3//! A high-performance library for translating shell commands and file paths between
4//! different operating systems. Designed for integration into terminal emulators
5//! and cross-platform tools.
6//!
7//! ## Features
8//!
9//! - **Command Translation**: Translate shell commands with flag support
10//! - **Path Translation**: Bidirectional file path translation (Windows ↔ Unix)
11//! - **OS Detection**: Runtime detection of the current operating system
12//! - **High Performance**: Static lookup tables with lazy initialization
13//!
14//! ## Command Translation Example
15//!
16//! ```
17//! use cmdx::{translate_command, Os};
18//!
19//! // Translate a Windows command to Linux
20//! let result = translate_command("dir /w", Os::Windows, Os::Linux);
21//! assert!(result.is_ok());
22//! assert!(result.unwrap().command.contains("ls"));
23//!
24//! // Translate a Linux command to Windows
25//! let result = translate_command("ls -la", Os::Linux, Os::Windows);
26//! assert!(result.is_ok());
27//! assert!(result.unwrap().command.contains("dir"));
28//! ```
29//!
30//! ## Path Translation Example
31//!
32//! ```
33//! use cmdx::{translate_path, Os};
34//!
35//! // Windows to Linux path
36//! let result = translate_path("C:\\Users\\john\\file.txt", Os::Windows, Os::Linux);
37//! assert!(result.is_ok());
38//! assert_eq!(result.unwrap().path, "/mnt/c/Users/john/file.txt");
39//!
40//! // Linux to Windows path
41//! let result = translate_path("/mnt/c/Users/john", Os::Linux, Os::Windows);
42//! assert!(result.is_ok());
43//! assert_eq!(result.unwrap().path, "C:\\Users\\john");
44//! ```
45//!
46//! ## Terminal Emulator Integration
47//!
48//! ```
49//! use cmdx::{translate_command, translate_path, detect_os, Os};
50//!
51//! // Detect the current OS at runtime
52//! let current_os = detect_os();
53//!
54//! // Translate user input for a different target OS
55//! fn process_input(input: &str, target_os: Os) -> String {
56//!     let current = cmdx::detect_os();
57//!     
58//!     // Try command translation first
59//!     if let Ok(result) = cmdx::translate_command(input, current, target_os) {
60//!         return result.command;
61//!     }
62//!     
63//!     // Fall back to path translation if it looks like a path
64//!     if let Ok(result) = cmdx::translate_path(input, current, target_os) {
65//!         return result.path;
66//!     }
67//!     
68//!     input.to_string()
69//! }
70//! ```
71
72pub mod translator;
73
74// Command translation exports
75pub use translator::command_map::{CommandMapping, FlagMapping, is_native_command, is_target_command_for_os};
76pub use translator::engine::{translate_command, translate_command_str, translate_batch, translate_compound_command, translate_full, translate_script_extension, translate_shebang, TranslationResult, TranslationError};
77
78// Path translation exports
79pub use translator::path::{translate_path, translate_path_str, translate_path_auto, translate_paths, PathTranslation, PathError, is_windows_path, is_unix_path};
80
81// Environment variable translation exports
82pub use translator::env::{translate_env_vars, translate_with_env};
83
84// OS detection exports
85pub use translator::os::{Os, detect_os};