parent
3972001328
commit
dd8f120152
2 changed files with 10 additions and 4 deletions
|
@ -14,6 +14,8 @@
|
||||||
//! along with vnetod. If not, see <https://www.gnu.org/licenses/>.
|
//! along with vnetod. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//!
|
//!
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -31,6 +33,9 @@ under certain conditions;
|
||||||
"
|
"
|
||||||
)]
|
)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
|
#[clap(short = 'f', long, default_value = ".env")]
|
||||||
|
pub file: PathBuf,
|
||||||
|
|
||||||
#[clap(value_parser)]
|
#[clap(value_parser)]
|
||||||
pub section_names: Vec<String>,
|
pub section_names: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufWriter, Write},
|
io::{BufWriter, Write},
|
||||||
|
@ -27,15 +28,15 @@ use clap::Parser;
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
let cli = cli::Args::parse();
|
let cli = cli::Args::parse();
|
||||||
|
|
||||||
change_env_layout(&cli.section_names)?;
|
change_env_layout(&cli.file, &cli.section_names)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_env_layout(section_names: &[String]) -> Result<(), Error> {
|
fn change_env_layout(file: &Path, section_names: &[String]) -> Result<(), Error> {
|
||||||
let content = std::fs::read_to_string(".env").map_err(|_| Error::OpenFile)?;
|
let content = std::fs::read_to_string(file).map_err(|_| Error::OpenFile)?;
|
||||||
|
|
||||||
let mut writer = File::create(".env")
|
let mut writer = File::create(file)
|
||||||
.map_err(|_| Error::OpenFile)
|
.map_err(|_| Error::OpenFile)
|
||||||
.map(BufWriter::new)?;
|
.map(BufWriter::new)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue