ea_command/
interface.rs

1use clap::{ArgEnum, Parser, Subcommand, ValueHint};
2
3/// ea - Making command line output actionable
4///
5/// This tool captures paths from command line tools, and let you follow them up with actions.
6/// When you run a command line tool through `ea run`, its output containing file paths will be
7/// prefixed with a NUMBER. Afterwards, `ea print NUMBER` will output the associated path so that
8/// you can use it as part of other commands (e.g. `vim $(ea p 42)` to open path #42 in vim).
9///
10/// For more details, see `man ea`, or documentation at https://github.com/dduan/ea
11#[derive(Debug, Parser)]
12#[clap(author, version, about)]
13pub struct Interface {
14    #[clap(subcommand)]
15    pub subcommand: Option<Commands>,
16}
17
18#[derive(ArgEnum, Clone, Debug)]
19pub enum Style {
20    Grouped,
21    Linear,
22    Search,
23    Rust,
24    Py,
25}
26
27#[derive(Debug, Subcommand)]
28pub enum Commands {
29    /// Run EXECUTABLE through `ea`. Expecting its output to be the format of STYLE. Arguments for
30    /// EXECUTABLE must come after `--`. For example, `rg Vec src` becomes:
31    ///
32    /// ea run grouped rg -- Vec src
33    ///
34    /// (rg's default output is in the "grouped" STYLE).
35    Run {
36        /// Format of output from EXECUTABLE. ea looks for file paths, lines, and columns within
37        /// the file at the path. A file path can have one or more "locations". A location has at
38        /// least a file path, and a line number, with an optional column.
39        ///
40        /// [grouped]: A file path followed by a list of locations, then the next file path and its
41        ///            locations, etc. Example: ripgrep's default output format.
42        ///
43        /// [linear]:  An location on each line. Example: fd/find's default output format.
44        ///
45        /// [search]:  Locations at the start of line, with additional content on the same line,
46        ///            followed by lots of other content, followed by another location. Example:
47        ///            clang/swift's default format.
48        ///
49        /// For more explanation, see `man ea`, or documentation at http://github.com/dduan/ea
50        #[clap(arg_enum)]
51        style: Style,
52        #[clap(value_hint = ValueHint::CommandName)]
53        /// The command to execute.
54        executable: String,
55        #[clap(last = true)]
56        /// Arguments for EXECUTABLE. Must be separated from EXECUTABLE with `--` (two dashes).
57        arguments: Vec<String>,
58        /// Write debug info at <debug_files_base_name.*>
59        #[clap(long, value_name = "debug_files_base_name", value_hint = ValueHint::FilePath)]
60        debug: Option<String>,
61    },
62
63    /// List locations found from the latest `ea run` output. This is the default subcommand.
64    /// Running `ea` is the same as running `ea list`.
65    List,
66
67    /// Print the location info associated with NUMBER. Optionally, customize the output FORMAT.
68    /// Also availble as the shorthand `ea p ...`
69    #[clap(alias("p"))]
70    Print {
71        /// The number associated with a file location from the latest `ea run` output.
72        #[clap(required = true)]
73        number: usize,
74        /// A string representing the format of the location to be printed. `{path}`, `{line}`, and `{column}`
75        /// in this string will be replaced with corresponding values within the location. For
76        /// example, 'L{line}C{column} @ {path}' might print out 'L23C11 @ path/to/file'. If line
77        /// or column info isn't available, they'll be filled with '0'.
78        #[clap(default_value = "{path}")]
79        format: String,
80    },
81}