mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Add embedded struct output support for flags.
We use a dotted syntax for now but we might want to support other separators in a future commit.
This commit is contained in:
parent
bafe5b3c30
commit
b31e95567d
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ucg"
|
||||
version = "0.0.1"
|
||||
version = "0.0.2"
|
||||
authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"]
|
||||
description = "A configuration generation grammar."
|
||||
repository = "https://github.com/zaphar/ucg"
|
||||
|
2
TODO.md
2
TODO.md
@ -17,4 +17,6 @@ organiztion for a given configuration structure. Some options here could be
|
||||
|
||||
# Minor Fixes and Polish
|
||||
|
||||
* Flags should allow different seperators for prefixed flags.
|
||||
* None value types
|
||||
* YAML export
|
@ -1 +0,0 @@
|
||||
dbconn_list=db_conn1='db1.prod.net:3306/testdb' db_conn2='db2.prod.net:3306/testdb' tmpldir='./templates'
|
@ -1 +0,0 @@
|
||||
--db_conn1 'db1.prod.net:3306/testdb' --db_conn2 'db2.prod.net:3306/testdb' --dbconn_list --tmpldir './templates'
|
@ -19,8 +19,10 @@ let db_conns = [db_conn1.conn_string, db_conn2.conn_string];
|
||||
|
||||
// Our server configuration.
|
||||
let server_config = {
|
||||
dbconn_list = db_conns,
|
||||
db_conn1 = db_conns.0, // connection one
|
||||
db_conn2 = db_conns.1,
|
||||
tmpldir = "./templates"
|
||||
tmpldir = "./templates",
|
||||
prefix = {
|
||||
foo = "bar"
|
||||
}
|
||||
};
|
@ -437,6 +437,12 @@ pub struct Positioned<T> {
|
||||
pub val: T,
|
||||
}
|
||||
|
||||
impl<T: std::fmt::Display> std::fmt::Display for Positioned<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
write!(f, "{}", self.val)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Positioned<T> {
|
||||
/// Constructs a new Positioned<T> with a value, line, and column information.
|
||||
pub fn new(v: T, l: usize, c: usize) -> Self {
|
||||
|
@ -28,7 +28,7 @@ impl FlagConverter {
|
||||
FlagConverter {}
|
||||
}
|
||||
|
||||
fn write(&self, v: &Val, w: &mut Write) -> Result<()> {
|
||||
fn write(&self, pfx: &str, v: &Val, w: &mut Write) -> Result<()> {
|
||||
match v {
|
||||
&Val::Float(ref f) => {
|
||||
try!(write!(w, "{} ", f));
|
||||
@ -46,12 +46,17 @@ impl FlagConverter {
|
||||
&Val::Tuple(ref flds) => {
|
||||
for &(ref name, ref val) in flds.iter() {
|
||||
if val.is_tuple() {
|
||||
eprintln!("Skipping embedded tuple...");
|
||||
return Ok(());
|
||||
let new_pfx = format!("{}{}.", pfx, name);
|
||||
try!(self.write(&new_pfx, val, w));
|
||||
} else {
|
||||
if name.val.chars().count() > 1 || pfx.chars().count() > 0 {
|
||||
try!(write!(w, "--{}{} ", pfx, name.val));
|
||||
} else {
|
||||
try!(write!(w, "-{} ", name.val));
|
||||
}
|
||||
// TODO(jwall): What if the value is a tuple?
|
||||
try!(self.write(pfx, &val, w));
|
||||
}
|
||||
try!(write!(w, "--{} ", name.val));
|
||||
// TODO(jwall): What if the value is a tuple?
|
||||
try!(self.write(&val, w));
|
||||
}
|
||||
}
|
||||
&Val::Macro(ref _def) => {
|
||||
@ -65,6 +70,6 @@ impl FlagConverter {
|
||||
|
||||
impl Converter for FlagConverter {
|
||||
fn convert(&self, v: Rc<Val>, mut w: Box<Write>) -> Result<()> {
|
||||
self.write(&v, &mut w)
|
||||
self.write("", &v, &mut w)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user