tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

main.rs (1533B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 mod cli;
      6 mod command;
      7 mod debug_commands;
      8 mod gui;
      9 mod net;
     10 mod script_commands;
     11 mod wrench;
     12 
     13 use argh::FromArgs;
     14 use std::str;
     15 
     16 // Main entry point for the WR debugger, which defaults to CLI mode but can also run in GUI mode.
     17 
     18 #[derive(Debug, Copy, Clone)]
     19 enum Mode {
     20    Repl,
     21    Gui,
     22 }
     23 
     24 impl str::FromStr for Mode {
     25    type Err = &'static str;
     26 
     27    fn from_str(s: &str) -> Result<Mode, &'static str> {
     28        match s {
     29            "repl" => Ok(Mode::Repl),
     30            "gui" => Ok(Mode::Gui),
     31            _ => Err("Invalid mode"),
     32        }
     33    }
     34 }
     35 
     36 #[derive(FromArgs, Debug)]
     37 /// WebRender Shell arguments
     38 struct Args {
     39    #[argh(positional)]
     40    #[argh(default = "Mode::Repl")]
     41    /// mode to run the shell in
     42    mode: Mode,
     43 
     44    #[argh(option, short = 'h')]
     45    #[argh(default = "\"localhost:3583\".into()")]
     46    /// host to connect to
     47    host: String,
     48 }
     49 
     50 fn main() {
     51    let args: Args = argh::from_env();
     52 
     53    let mut cmd_list = command::CommandList::new();
     54    debug_commands::register(&mut cmd_list);
     55    script_commands::register(&mut cmd_list);
     56 
     57    match args.mode {
     58        Mode::Repl => {
     59            let cli = cli::Cli::new(&args.host, cmd_list);
     60            cli.run();
     61        }
     62        Mode::Gui => {
     63            let gui = gui::Gui::new(&args.host, cmd_list);
     64            gui.run();
     65        }
     66    }
     67 }