Skip to content

Commit

Permalink
Slawlor/dev (#3)
Browse files Browse the repository at this point in the history
* initial commit of REPL interface

* Adding test utility

* Initial clippy + rustfmt to cleanup build pipeline

* PR CI additions

* cargo test abiguity

* Added async trait to Repl, for non-async usage

* Crate rename to rustyrepl

* Generate the process() logic via macro for better reusability and less code duplication

* Adding publish pipeline

* missing default flag

* adding async tests

* fix async test pipeline

* ci syntax

Co-authored-by: Sean Lawlor <[email protected]>
  • Loading branch information
slawlor and slawlor authored Aug 30, 2022
1 parent cca2b06 commit 1784a2d
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 234 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]
pull_request:
types: [opened, edited, reopened, synchronize, ready_for_review]

jobs:
test:
Expand All @@ -22,10 +22,15 @@ jobs:
with:
toolchain: ${{matrix.toolchain}}
override: true
- name: Run tests
- name: Run default test suite
uses: actions-rs/cargo@v1
with:
command: test
- name: Run ReplyRepl async tests
uses: actions-rs/cargo@v1
with:
command: test
args: --package rustyrepl --features async

clippy:
name: Clippy
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish

on:
release:
types: [published]

jobs:
publish:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}
- uses: actions/checkout@main
- name: Login to crates.io
run: cargo login $CRATES_IO_TOKEN
env:
CRATES_IO_TOKEN: ${{ secrets.crates_io_token }}
- name: Dry run publish rustyrepl
run: cargo publish --dry-run --manifest-path Cargo.toml -p rustyrepl
- name: Publish crate rustyrepl
run: cargo publish --manifest-path Cargo.toml -p rustyrepl
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.crates_io_token }}
64 changes: 64 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'rustyrepl'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=rustyrepl"
],
"filter": {
"name": "rustyrepl",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'repl-test'",
"cargo": {
"args": [
"build",
"--bin=repl-test",
"--package=repl-test"
],
"filter": {
"name": "repl-test",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'repl-test'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=repl-test",
"--package=repl-test"
],
"filter": {
"name": "repl-test",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]

members = [
"repl",
"rustyrepl",
"repl-test"
]
4 changes: 1 addition & 3 deletions repl-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ license = "MIT"
edition = "2018"
publish = false

# [features]

[dependencies]
anyhow = { version = "1", features = ["backtrace"] }
async-trait = "0.1"
Expand All @@ -23,4 +21,4 @@ rustyline = "10"
thread-id = "3"
tokio = { version = "1.10", features = ["full"] }

repl = { path = "../repl" }
rustyrepl = { path = "../rustyrepl", features = ["async"] }
10 changes: 7 additions & 3 deletions repl-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use rustyrepl::{Repl, ReplCommandProcessor};

mod console_log;

Expand All @@ -39,7 +40,7 @@ pub struct Cli {
pub struct CliProcessor {}

#[async_trait::async_trait]
impl repl::ReplCommandProcessor<Cli> for CliProcessor {
impl ReplCommandProcessor<Cli> for CliProcessor {
fn is_quit(&self, command: &str) -> bool {
matches!(command, "quit" | "exit")
}
Expand All @@ -62,8 +63,11 @@ async fn main() -> Result<()> {
.map(|()| log::set_max_level(LOGGER.level.to_level_filter()))
.expect("Failed to set up logging");

let processor: Box<dyn repl::ReplCommandProcessor<Cli>> = Box::new(CliProcessor {});
let processor: Box<dyn ReplCommandProcessor<Cli>> = Box::new(CliProcessor {});
// create a dummy test history file
let history_file = ".test_history".to_string();
let some_history_file = Some(history_file);

let mut repl = repl::Repl::<Cli>::new(processor, None, Some(">>".to_string()))?;
let mut repl = Repl::<Cli>::new(processor, some_history_file, Some(">> ".to_string()))?;
repl.process().await
}
27 changes: 0 additions & 27 deletions repl/src/commands.rs

This file was deleted.

20 changes: 0 additions & 20 deletions repl/src/lib.rs

This file was deleted.

169 changes: 0 additions & 169 deletions repl/src/repl.rs

This file was deleted.

Loading

0 comments on commit 1784a2d

Please sign in to comment.