|
4 | 4 | use args::{Args, SubCommand}; |
5 | 5 | use clap::{CommandFactory, Parser}; |
6 | 6 | use clap_complete::generate; |
| 7 | +use dsc_lib::progress::ProgressFormat; |
7 | 8 | use mcp::start_mcp_server; |
8 | 9 | use rust_i18n::{i18n, t}; |
9 | | -use std::{io, io::Read, process::exit}; |
| 10 | +use std::{io, process::exit}; |
10 | 11 | use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind}; |
11 | 12 | use tracing::{error, info, warn, debug}; |
12 | | -use dsc_lib::progress::ProgressFormat; |
13 | 13 |
|
14 | | -use crate::util::EXIT_INVALID_INPUT; |
| 14 | +use crate::util::{EXIT_INVALID_INPUT, get_input}; |
15 | 15 |
|
16 | 16 | #[cfg(debug_assertions)] |
17 | 17 | use crossterm::event; |
@@ -54,38 +54,11 @@ fn main() { |
54 | 54 | generate(shell, &mut cmd, "dsc", &mut io::stdout()); |
55 | 55 | }, |
56 | 56 | SubCommand::Config { subcommand, parameters, parameters_file, system_root, as_group, as_assert, as_include } => { |
57 | | - // Read parameters from file if provided |
58 | | - let file_params = if let Some(file_name) = ¶meters_file { |
59 | | - if file_name == "-" { |
60 | | - info!("{}", t!("main.readingParametersFromStdin")); |
61 | | - let mut stdin = Vec::<u8>::new(); |
62 | | - match io::stdin().read_to_end(&mut stdin) { |
63 | | - Ok(_) => { |
64 | | - match String::from_utf8(stdin) { |
65 | | - Ok(input) => Some(input), |
66 | | - Err(err) => { |
67 | | - error!("{}: {err}", t!("util.invalidUtf8")); |
68 | | - exit(EXIT_INVALID_INPUT); |
69 | | - } |
70 | | - } |
71 | | - }, |
72 | | - Err(err) => { |
73 | | - error!("{}: {err}", t!("util.failedToReadStdin")); |
74 | | - exit(EXIT_INVALID_INPUT); |
75 | | - } |
76 | | - } |
77 | | - } else { |
78 | | - info!("{}: {file_name}", t!("main.readingParametersFile")); |
79 | | - match std::fs::read_to_string(file_name) { |
80 | | - Ok(content) => Some(content), |
81 | | - Err(err) => { |
82 | | - error!("{} '{file_name}': {err}", t!("main.failedReadingParametersFile")); |
83 | | - exit(util::EXIT_INVALID_INPUT); |
84 | | - } |
85 | | - } |
86 | | - } |
87 | | - } else { |
| 57 | + let params = get_input(None, parameters_file.as_ref()); |
| 58 | + let file_params = if params.is_empty() { |
88 | 59 | None |
| 60 | + } else { |
| 61 | + Some(params) |
89 | 62 | }; |
90 | 63 |
|
91 | 64 | let merged_parameters = match (file_params, parameters) { |
|
0 commit comments