Skip to content

Commit

Permalink
Allow import/export from stdio for settings (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Mobarak authored Feb 19, 2022
1 parent 72b17ca commit fe010ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ rustflags = [
]

[alias]
files = "run --bin swift-files --no-default-features --features env_logger,indicatif --"
settings = "run --bin swift-settings --no-default-features --features env_logger --"
swift-files = "run --bin swift-files --no-default-features --features env_logger,indicatif --"
swift-settings = "run --bin swift-settings --no-default-features --features env_logger --"
18 changes: 16 additions & 2 deletions console_backend/src/settings_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ impl SettingsTab {
}

pub fn export(&self, path: &Path) -> Result<()> {
let mut f = fs::File::create(path)?;
if path.to_string_lossy() == "-" {
self.export_impl(std::io::stdout())
} else {
self.export_impl(fs::File::create(path)?)
}
}

fn export_impl<T: std::io::Write>(&self, mut f: T) -> Result<()> {
let settings = self.settings.lock();
let groups = settings.groups();
let mut conf = Ini::new();
Expand All @@ -187,7 +194,14 @@ impl SettingsTab {
}

pub fn import(&self, path: &Path) -> Result<()> {
let mut f = fs::File::open(path)?;
if path.to_string_lossy() == "-" {
self.import_impl(std::io::stdin())
} else {
self.import_impl(fs::File::create(path)?)
}
}

pub fn import_impl<T: std::io::Read>(&self, mut f: T) -> Result<()> {
let conf = Ini::read_from(&mut f)?;
let old_ethernet = self.set_if_group_changes(
&conf,
Expand Down

0 comments on commit fe010ab

Please sign in to comment.