#cli #clash

nightly bin+lib clashctl

A TUI & CLI to interact with clash RESTful API

5 unstable releases

Uses new Rust 2021

new 0.3.0-alpha.3 Nov 27, 2021
0.3.0-alpha.2 Nov 25, 2021
0.2.2 Nov 6, 2021
0.1.0 Oct 24, 2021

#289 in Command line utilities

Download history 11/week @ 2021-10-19 4/week @ 2021-10-26 15/week @ 2021-11-02 3/week @ 2021-11-09 6/week @ 2021-11-16 53/week @ 2021-11-23

77 downloads per month

MIT license

155KB
4.5K SLoC

Clashctl

About

Easy-to-use TUI & CLI to interact with Clash RESTful API.

Screenshots

Status panel

Status panel

Proxies panel

Proxies panel

Installing

From crates.io

$ cargo install clashctl --vers 0.3.0-alpha.3 --all-features

Compile from source

$ git clone https://github.com/George-Miao/clashctl.git
$ cd clashctl
$ cargo install --features "cli, ui" --path .

Getting Started

Use command without subcommands defaults to open TUI:

$ clashctl

# Equals

$ clashctl tui

Or use a subcommand to use the cli:

$ clashctl proxy list

---------------------------------------------------------
TYPE                DELAY   NAME
---------------------------------------------------------
selector            -       All

    URLTest         -       Auto-All
    ShadowsocksR    19      SomeProxy-1
    Vmess           177     SomeProxy-2
    Vmess           137     SomeProxy-3
    Shadowsocks     143     SomeProxy-4

---------------------------------------------------------

Features

  • Pretty terminal UI
  • Change proxies
  • Display proxies, with filter and sorting supported, in both plain and grouped mode
  • Store and use multiple servers
  • Generate completion script (by clap_generate)
  • Manage multiple servers

Done & TODO

  • Cli
    • Manage servers
    • Sort proxies
    • More features
  • TUI
    • Status Panel
    • Proxies Panel
      • Update proxy
      • Test latency
      • Sort by {Original, LatencyAsc, LatencyDsc, NameAsc, NameDsc}
    • Rules Panel
    • Connections Panel
      • Sort
    • Log Panel
    • Debug Panel
    • Config Panel
      • Update clash configs
      • Update clashctl configs
    • Search
    • (Maybe?) mouse support

Prerequisites

You will need nightly rust environment (Cargo & rustc) to compile and install

Usage

Use the TUI

  • Use the cli to config servers (for now)
  • Use number to navigate between tabs
  • Space to hold the list (and therefor move the list)
  • Arrow key to move the list under Hold mode
  • [^d] open debug panel

Use the CLI

$ clashctl -h
clashctl

George Miao <gm@miao.dev>

CLI used to interact with Clash RESTful API

USAGE:
    clashctl [OPTIONS] <SUBCOMMAND>

OPTIONS:
    -c, --config <CONFIG>      Path of config file. Default to ~/.config/clashctl/config.ron
    -h, --help                 Print help information
    -t, --timeout <TIMEOUT>    Timeout of requests, in ms [default: 2000]
    -v, --verbose              Verbosity. Default: INFO, -v DEBUG, -vv TRACE
    -V, --version              Print version information

SUBCOMMANDS:
    completion    Generate auto-completion scripts
    help          Print this message or the help of the given subcommand(s)
    proxy         Interacting with proxies
    server        Interacting with servers

Use as a crate

# cargo.toml

[dependencies]
clashctl = "*"

Then in your project:

use clashctl::Clash;

fn main() {
  let clash = Clash::builder("http://example.com:9090").unwrap().build();
  println!("Clash version is {:?}", clash.get_version().unwrap())
}

Development

clashctl comes with a justfile to speed up your development. Especially the command just dev, managed to reproduce the hot reload function in front-end development, with cargo-watch.

Just commands

just dev [ alias: d ]

Hot reload development, auto reload on cargo-check approved changes, with all features enabled

just run {{ Args }} [ alias: r ]

Run with feature cli & ui

just ui

Run UI only

just cli

Run CLI only

just build [ alias: b ]

Build in release mode with feature cli & ui

just add

Add an optional dependency, requires cargo-edit

Project structure

$ tree src -L 2
src
├── api.rs            # Clash API, with struct `Clash`, export by default
├── bin               # Binary dir
│   ├── cli.rs        # Cli only
│   ├── cli_ui.rs     # Both cli and ui
│   └── ui.rs         # Ui only
├── cli               # Feature `cli`, depends on clap
│   └── ...
├── error.rs          # Error
├── interactive       # Feature `interactive`, shared code of `cli` and `ui`
│   └── ...
├── lib.rs            # Lib entrance
├── model             # Models, export by default
│   └── ...
├── test              # Test codes
│   └── ...
└── ui                # Feature `ui`
    └── ...

Dependencies

~6–8MB
~170K SLoC

"a