Skip to content

Commit fe010ab

Browse files
author
Jason Mobarak
authored
Allow import/export from stdio for settings (#435)
1 parent 72b17ca commit fe010ab

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.cargo/config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ rustflags = [
1111
]
1212

1313
[alias]
14-
files = "run --bin swift-files --no-default-features --features env_logger,indicatif --"
15-
settings = "run --bin swift-settings --no-default-features --features env_logger --"
14+
swift-files = "run --bin swift-files --no-default-features --features env_logger,indicatif --"
15+
swift-settings = "run --bin swift-settings --no-default-features --features env_logger --"

console_backend/src/settings_tab.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ impl SettingsTab {
171171
}
172172

173173
pub fn export(&self, path: &Path) -> Result<()> {
174-
let mut f = fs::File::create(path)?;
174+
if path.to_string_lossy() == "-" {
175+
self.export_impl(std::io::stdout())
176+
} else {
177+
self.export_impl(fs::File::create(path)?)
178+
}
179+
}
180+
181+
fn export_impl<T: std::io::Write>(&self, mut f: T) -> Result<()> {
175182
let settings = self.settings.lock();
176183
let groups = settings.groups();
177184
let mut conf = Ini::new();
@@ -187,7 +194,14 @@ impl SettingsTab {
187194
}
188195

189196
pub fn import(&self, path: &Path) -> Result<()> {
190-
let mut f = fs::File::open(path)?;
197+
if path.to_string_lossy() == "-" {
198+
self.import_impl(std::io::stdin())
199+
} else {
200+
self.import_impl(fs::File::create(path)?)
201+
}
202+
}
203+
204+
pub fn import_impl<T: std::io::Read>(&self, mut f: T) -> Result<()> {
191205
let conf = Ini::read_from(&mut f)?;
192206
let old_ethernet = self.set_if_group_changes(
193207
&conf,

0 commit comments

Comments
 (0)