Skip to content

Commit

Permalink
feat: Iroh console (REPL) and restructured CLI (#1356)
Browse files Browse the repository at this point in the history
## Description

This adds a REPL to the main `iroh` binary. It builds upon #1216.


* The REPL embeds all commands that operate via the RPC client - which,
currently, is everything but `provide` (which should be called `start`),
`get` and `doctor`.

* The REPL has two new, REPL-only commands: `set-doc` and `set-author`.
`set-doc` changes the state of the REPL: author and document will be
displayed above the input line, and the document commands (`set`, `get`,
`list` , `share` etc) will be available top-level.

* Most of the changes in `src/commands.rs` only move code and the
`rpc_port` option around, the individual commands are not changed in
this PR.

## Notes & open questions

* The document and author IDs in the `list` commands are currently
printed in hex. Should change to base32.

* I'm not yet super sure about the `set-doc` and `set-author` commands.
Another path might be to dig more into a pwd-like structure and have a
`cd` command or so. This could then also move further into documents.
I'm not sure how the author fits in here.

* When in the level of a document, there's a conflict between the `doc
list` command (which is just `list` then) and the top-level `list`
command (to list blobs and collections). Not sure yet what the solution
is. For now I embedded only the `sync` commands on the doc level, but I
think I'd prefer to have the global set of commands not change between
levels. Maybe we just rename the top-level `list` command to `blobs` and
group the other blob-related commands (`add', a tbd `get` via RPC,
possibly `export`) there.

* The REPL embeds all the existing RPC CLI commands. For this I changed
the structure of the `src/cli/commands.rs` to a) split between
`RpcCommands` and `FullCommands` , the latter are the ones that start an
actual iroh node (plus doctor, wasn't sure about that for now). The
former all work atop the RPC client. For them to not create a new RPC
client for each REPL command, I moved the `--rpc-port` option to the top
level. This is not super correct, because it does not apply to
`provide`, `get`, `doctor`. Clap does not allow to scope an argument to
a set of subcommands by default, see [this
discussion](clap-rs/clap#5070 (comment)).
Still thinking about what the cleanest solution is.

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.

---------

Co-authored-by: dignifiedquire <me@dignifiedquire.com>
Co-authored-by: Asmir Avdicevic <asmir.avdicevic64@gmail.com>
Co-authored-by: Kasey <klhuizinga@gmail.com>
Co-authored-by: Brendan O'Brien <sparkle_pony_2000@qri.io>
  • Loading branch information
5 people authored Aug 24, 2023
1 parent 3f141be commit b73d950
Show file tree
Hide file tree
Showing 14 changed files with 980 additions and 508 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version = "1.67"
anyhow = { version = "1", features = ["backtrace"] }
bao-tree = { version = "0.6.3", features = ["tokio_fsm"], default-features = false }
bytes = "1"
data-encoding = "2.4.0"
derive_more = { version = "1.0.0-beta.1", features = ["debug", "display", "from", "try_into"] }
flume = "0.10.14"
futures = "0.3.25"
Expand All @@ -25,6 +26,7 @@ iroh-bytes = { version = "0.5.0", path = "../iroh-bytes" }
iroh-io = { version = "0.2.2" }
iroh-metrics = { version = "0.5.0", path = "../iroh-metrics", optional = true }
iroh-net = { version = "0.5.1", path = "../iroh-net" }
itertools = "0.11.0"
num_cpus = { version = "1.15.0" }
portable-atomic = "1"
iroh-sync = { version = "0.5.1", path = "../iroh-sync" }
Expand All @@ -51,26 +53,27 @@ console = { version = "0.15.5", optional = true }
dirs-next = { version = "2.0.0", optional = true }
indicatif = { version = "0.17", features = ["tokio"], optional = true }
multibase = { version = "0.9.1", optional = true }
rustyline = { version = "12.0.0", optional = true }
shell-words = { version = "1.1.0", optional = true }
shellexpand = { version = "3.1.0", optional = true }
tempfile = { version = "3.4", optional = true }
toml = { version = "0.7.3", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }
data-encoding = "2.4.0"
url = { version = "2.4", features = ["serde"] }
colored = { version = "2.0.4", optional = true }

# Examples
shell-words = { version = "1.1.0", optional = true }
shellexpand = { version = "3.1.0", optional = true }
rustyline = { version = "12.0.0", optional = true }
itertools = "0.11.0"
ed25519-dalek = { version = "2.0.0", features = ["serde", "rand_core"], optional = true }

[features]
default = ["cli", "metrics"]
cli = ["clap", "config", "console", "dirs-next", "indicatif", "multibase", "quic-rpc/quinn-transport", "tempfile", "tokio/rt-multi-thread", "tracing-subscriber", "flat-db", "mem-db", "iroh-collection"]
cli = ["clap", "config", "console", "dirs-next", "indicatif", "multibase", "quic-rpc/quinn-transport", "tempfile", "tokio/rt-multi-thread", "tracing-subscriber", "flat-db", "mem-db", "iroh-collection", "shell-words", "shellexpand", "rustyline", "colored", "toml"]
metrics = ["iroh-metrics"]
mem-db = []
flat-db = []
iroh-collection = []
test = []
example-sync = ["cli", "shell-words", "shellexpand", "rustyline"]
example-sync = ["cli"]

[dev-dependencies]
anyhow = { version = "1", features = ["backtrace"] }
Expand Down
Loading

0 comments on commit b73d950

Please sign in to comment.