Changed ConfigType trait to only return a string of variants, rather than a vec

This commit is contained in:
Aaron Lobb 2015-09-14 13:43:55 -07:00
parent cd9e9b5db0
commit d773580715
3 changed files with 18 additions and 35 deletions

View File

@ -17,7 +17,7 @@ extern crate rustfmt;
extern crate toml; extern crate toml;
use rustfmt::{WriteMode, run}; use rustfmt::{WriteMode, run};
use rustfmt::config::{Config, ConfigHelpVariantTypes}; use rustfmt::config::Config;
use std::env; use std::env;
use std::fs::{File, PathExt}; use std::fs::{File, PathExt};
@ -87,13 +87,7 @@ fn print_usage<S: Into<String>>(reason: S) {
reason.into()); reason.into());
for option in Config::get_docs() { for option in Config::get_docs() {
let variants = option.variant_names(); println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), option.variant_names());
let variant_names: String = match *variants {
ConfigHelpVariantTypes::UsizeConfig => "<unsigned integer>".into(),
ConfigHelpVariantTypes::BoolConfig => "<boolean>".into(),
ConfigHelpVariantTypes::EnumConfig(ref variants) => variants.join(", "),
};
println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), variant_names);
} }
} }

View File

@ -82,34 +82,28 @@ macro_rules! create_config {
$(pub $i: Option<$ty>),+ $(pub $i: Option<$ty>),+
} }
// This trait and the following impl blocks are there only so that we // This trait and the following impl blocks are there so that we an use
// can use UCFS inside the get_docs() function on builtin types for configs. // UCFS inside the get_docs() function on types for configs.
trait IsConfigType { pub trait ConfigType {
fn get_variant_names() -> Vec<&'static str>; fn get_variant_names() -> String;
} }
impl IsConfigType for bool { impl ConfigType for bool {
fn get_variant_names() -> Vec<&'static str> { fn get_variant_names() -> String {
unreachable!() String::from("<boolean>")
} }
} }
impl IsConfigType for usize { impl ConfigType for usize {
fn get_variant_names() -> Vec<&'static str> { fn get_variant_names() -> String {
unreachable!() String::from("<unsigned integer>")
} }
} }
pub struct ConfigHelpItem { pub struct ConfigHelpItem {
option_name: &'static str, option_name: &'static str,
doc_string : &'static str, doc_string : &'static str,
variant_names: ConfigHelpVariantTypes, variant_names: String,
}
pub enum ConfigHelpVariantTypes {
UsizeConfig,
BoolConfig,
EnumConfig(Vec<&'static str>),
} }
impl ConfigHelpItem { impl ConfigHelpItem {
@ -121,7 +115,7 @@ macro_rules! create_config {
self.doc_string self.doc_string
} }
pub fn variant_names(&self) -> &ConfigHelpVariantTypes { pub fn variant_names(&self) -> &String {
&self.variant_names &self.variant_names
} }
} }
@ -165,15 +159,10 @@ macro_rules! create_config {
pub fn get_docs() -> Vec<ConfigHelpItem> { pub fn get_docs() -> Vec<ConfigHelpItem> {
let mut options: Vec<ConfigHelpItem> = Vec::new(); let mut options: Vec<ConfigHelpItem> = Vec::new();
$( $(
let config_variant_type = match stringify!($ty) {
"bool" => ConfigHelpVariantTypes::BoolConfig,
"usize" => ConfigHelpVariantTypes::UsizeConfig,
_ => ConfigHelpVariantTypes::EnumConfig(<$ty>::get_variant_names()),
};
options.push(ConfigHelpItem { options.push(ConfigHelpItem {
option_name: stringify!($i), option_name: stringify!($i),
doc_string: stringify!($dstring), doc_string: stringify!($dstring),
variant_names: config_variant_type, variant_names: <$ty>::get_variant_names(),
}); });
)+ )+
options options

View File

@ -162,14 +162,14 @@ macro_rules! impl_enum_decodable {
} }
} }
impl $e { impl ::config::ConfigType for $e {
pub fn get_variant_names() -> Vec<&'static str> { fn get_variant_names() -> String {
let mut variants = Vec::new(); let mut variants = Vec::new();
$( $(
variants.push(stringify!($x)); variants.push(stringify!($x));
)* )*
variants variants.join(", ")
} }
} }
}; };