Skip to content

Commit

Permalink
varlink_generator: update cli and generate new testsuite output
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldh committed Dec 7, 2018
1 parent befa40e commit 8d6e999
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions varlink_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ failure = "0.1.2"
varlink_parser = { version = "2.1", path = "../varlink_parser" }
quote = "0.6"
proc-macro2 = "0.4"
getopts = "0"

This comment has been minimized.

Copy link
@ignatenkobrain

ignatenkobrain Dec 9, 2018

Contributor

Why not to use clippy?

This comment has been minimized.

Copy link
@haraldh

haraldh Dec 10, 2018

Author Collaborator

The executable can not be run anyway :-(

$ /home/harald/.cargo/bin/varlink-rust-generator
/home/harald/.cargo/bin/varlink-rust-generator: error while loading shared libraries: libproc_macro-520699affe05435a.so: cannot open shared object file: No such file or directory

This comment has been minimized.

Copy link
@ignatenkobrain

ignatenkobrain Dec 10, 2018

Contributor

That's because of old bug in cargo. Ping me on IRC and I will send you link to bug.

This comment has been minimized.

Copy link
@ignatenkobrain

[badges]
travis-ci = { repository = "varlink/rust" }
Expand Down
39 changes: 34 additions & 5 deletions varlink_generator/src/bin/varlink-rust-generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,51 @@ extern crate varlink_generator;
use std::env;
use std::fs::File;
use std::io;
use std::io::{Error, ErrorKind};
use std::io::{Read, Write};
use std::path::Path;

use varlink_generator::{generate, Result};

fn print_usage(program: &str, opts: &getopts::Options) {
let brief = format!("Usage: {} [VARLINK FILE]", program);
print!("{}", opts.usage(&brief));
}

fn main() -> Result<()> {
let args: Vec<_> = env::args().collect();
let mut reader: Box<Read> = match args.len() {
0 | 1 => Box::new(io::stdin()),
let program = args[0].clone();

let mut opts = getopts::Options::new();
opts.optflag("h", "help", "print this help menu");
opts.optflag("", "nosource", "don't print doc header and allow");

let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
eprintln!("{}", f.to_string());
print_usage(&program, &opts);
return Err(Error::from(ErrorKind::InvalidData).into());
}
};

if matches.opt_present("h") {
print_usage(&program, &opts);
return Ok(());
}

let tosource = !matches.opt_present("nosource");

let mut reader: Box<Read> = match matches.free.len() {
0 => Box::new(io::stdin()),
_ => {
if args[1] == "-" {
if matches.free[0] == "-" {
Box::new(io::stdin())
} else {
Box::new(File::open(Path::new(&args[1]))?)
Box::new(File::open(Path::new(&matches.free[0]))?)
}
}
};
let writer: &mut Write = &mut io::stdout();
generate(&mut reader, writer, true)
generate(&mut reader, writer, tosource)
}
8 changes: 4 additions & 4 deletions varlink_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ fn varlink_to_rust(

if tosource {
ts.extend(quote!(
#![doc = "This file was automatically generated by the varlink rust generator" ]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
));
#![doc = "This file was automatically generated by the varlink rust generator" ]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
));
}

ts.extend(quote!(
Expand Down
Loading

0 comments on commit 8d6e999

Please sign in to comment.