MCPcopy Create free account
hub / github.com/arraypad/each / run

Function run

src/main.rs:120–269  ·  view source on GitHub ↗
(
	args: Command,
	mut formats: IndexMap<&'static str, Box<dyn Format>>,
)

Source from the content-addressed store, hash-verified

118}
119
120fn run(
121 args: Command,
122 mut formats: IndexMap<&'static str, Box<dyn Format>>,
123) -> Result<(), EachError> {
124 let arg_matches = args.get_matches();
125 info!("arguments: {:?}", arg_matches);
126
127 for (format_id, ref mut format) in &mut formats {
128 format
129 .set_arguments(&arg_matches)
130 .map_err(|e| EachError::Usage {
131 message: format!("Invalid argument for format {}: {}", format_id, e),
132 })?;
133 }
134
135 let max_procs = if let Some(max_procs_str) = arg_matches.value_of("max-procs") {
136 max_procs_str
137 .parse::<usize>()
138 .map_err(|e| EachError::Usage {
139 message: format!("Invalid max-procs: {} ({})", &max_procs_str, e),
140 })?
141 } else {
142 1
143 };
144
145 rayon::ThreadPoolBuilder::new()
146 .num_threads(max_procs)
147 .build_global()
148 .expect("build_global already called");
149
150 let mut readers: Vec<(Option<String>, CachedReader)> = Vec::new();
151
152 if let Some(input_paths) = arg_matches.values_of("input") {
153 for input_path in input_paths {
154 let path = Path::new(&input_path);
155 let ext = path
156 .extension()
157 .map(|ext| ext.to_string_lossy().to_string());
158 let reader = Box::new(FileReader::new(&input_path).map_err(|e| EachError::Data {
159 message: format!("Couldn't open file {}: {}", &input_path, e),
160 })?);
161
162 let cached = CachedReader::new(reader);
163
164 readers.push((ext, cached));
165 }
166 } else if atty::is(atty::Stream::Stdin) {
167 return Err(EachError::Usage {
168 message: "No input provided".to_owned(),
169 });
170 } else {
171 let reader = Box::new(std::io::stdin());
172 let cached = CachedReader::new(reader);
173 readers.push((None, cached));
174 }
175
176 let action: Option<Action> = match arg_matches.values_of("command") {
177 Some(ref mut commands) => {

Callers 1

mainFunction · 0.85

Calls 5

guess_formatFunction · 0.85
processFunction · 0.85
set_argumentsMethod · 0.45
parseMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected