Skip to content

Commit

Permalink
#13: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 5, 2022
1 parent 52c0eb6 commit 9151676
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
49 changes: 28 additions & 21 deletions src/bin/reo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

extern crate reo;

use anyhow::Context;
use clap::{crate_version, AppSettings, Arg, ArgAction, Command};
use log::{debug, LevelFilter};
use reo::da;
use reo::universe::Universe;
use reo::setup::setup;
use reo::gmi::Gmi;
use reo::setup::setup;
use reo::universe::Universe;
use simple_logger::SimpleLogger;
use std::fs;
use std::path::Path;
use anyhow::{Context};
use clap::{AppSettings, Arg, ArgAction, Command, crate_version};
use log::{debug, LevelFilter};
use simple_logger::SimpleLogger;

pub fn main() {
let matches = Command::new("reo")
Expand All @@ -41,7 +41,7 @@ pub fn main() {
.long("verbose")
.required(false)
.takes_value(false)
.help("Print all possible debug messages")
.help("Print all possible debug messages"),
)
.arg(
Arg::new("file")
Expand All @@ -51,7 +51,7 @@ pub fn main() {
.required(false)
.help("Name of a single .gmi file to work with")
.takes_value(true)
.action(ArgAction::Set)
.action(ArgAction::Set),
)
.arg(
Arg::new("home")
Expand All @@ -61,7 +61,7 @@ pub fn main() {
.required(false)
.help("Directory with .gmi files")
.takes_value(true)
.action(ArgAction::Set)
.action(ArgAction::Set),
)
.subcommand_required(true)
.allow_external_subcommands(true)
Expand All @@ -74,21 +74,22 @@ pub fn main() {
.required(true)
.help("Fully qualified object name")
.takes_value(false)
.action(ArgAction::Set)
.action(ArgAction::Set),
)
.arg_required_else_help(true)
.arg_required_else_help(true),
)
.get_matches();
let mut logger = SimpleLogger::new().without_timestamps();
logger = logger.with_level(
if matches.contains_id("verbose") {
LevelFilter::Trace
} else {
LevelFilter::Info
}
);
logger = logger.with_level(if matches.contains_id("verbose") {
LevelFilter::Trace
} else {
LevelFilter::Info
});
logger.init().unwrap();
debug!("argv: {}", std::env::args().collect::<Vec<String>>().join(" "));
debug!(
"argv: {}",
std::env::args().collect::<Vec<String>>().join(" ")
);
match matches.subcommand() {
Some(("dataize", subs)) => {
let object = subs.get_one::<String>("object").unwrap();
Expand All @@ -103,10 +104,16 @@ pub fn main() {
let mut total = 0;
if matches.contains_id("path") {
let file = Path::new(matches.value_of("path").unwrap());
debug!("Deploying instructions from a single file '{}'", file.display());
debug!(
"Deploying instructions from a single file '{}'",
file.display()
);
total += Gmi::from_file(file).unwrap().deploy_to(&mut uni).unwrap();
} else {
debug!("Deploying instructions from a directory '{}'", cwd.display());
debug!(
"Deploying instructions from a directory '{}'",
cwd.display()
);
uni.add(0).unwrap();
total += setup(&mut uni, cwd).unwrap();
}
Expand Down
3 changes: 2 additions & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub fn setup(uni: &mut Universe, dir: &Path) -> Result<u32> {
}
}
gmi.set_root(root);
total += gmi.deploy_to(uni)
total += gmi
.deploy_to(uni)
.context(format!("Failed to deploy '{}'", path.display()))?;
}
Ok(total)
Expand Down
30 changes: 16 additions & 14 deletions tests/reo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use std::fs::File;
use predicates::prelude::*;
use tempfile::TempDir;
use anyhow::{Result};
use std::io::Write;
use anyhow::Result;
use glob::glob;
use predicates::prelude::predicate;
use predicates::prelude::*;
use std::fs::File;
use std::io::Write;
use tempfile::TempDir;

#[test]
fn prints_help() {
assert_cmd::Command::cargo_bin("reo").unwrap()
assert_cmd::Command::cargo_bin("reo")
.unwrap()
.arg("--help")
.assert()
.success()
.stdout(
predicate::str::contains("GMI to Rust")
.and(predicate::str::contains("--home"))
);
.stdout(predicate::str::contains("GMI to Rust").and(predicate::str::contains("--home")));
}

#[test]
fn prints_version() {
assert_cmd::Command::cargo_bin("reo").unwrap()
assert_cmd::Command::cargo_bin("reo")
.unwrap()
.arg("--version")
.assert()
.success();
Expand All @@ -54,9 +53,11 @@ fn dataizes_simple_gmi() -> Result<()> {
ADD('$ν1');
BIND('$ε2', 'ν0', '$ν1', 'foo');
DATA('$ν1', 'ff ff');
".as_bytes()
"
.as_bytes(),
)?;
assert_cmd::Command::cargo_bin("reo").unwrap()
assert_cmd::Command::cargo_bin("reo")
.unwrap()
.arg(format!("--home={}", tmp.path().display()))
.arg("dataize")
.arg("foo")
Expand All @@ -71,7 +72,8 @@ fn dataizes_all_gmi_tests() -> Result<()> {
for f in glob("gmi-tests/*.gmi")? {
let p = f?;
let path = p.as_path();
assert_cmd::Command::cargo_bin("reo").unwrap()
assert_cmd::Command::cargo_bin("reo")
.unwrap()
.arg(format!("--file={}", path.display()))
.arg("--verbose")
.arg("dataize")
Expand Down

0 comments on commit 9151676

Please sign in to comment.