Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyLeite committed Sep 6, 2023
1 parent bf8ab0f commit 6681f77
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum PluginCommand {

#[arg(short = 'd', long, default_value = "false")]
build_with_dev: bool,

#[arg(short = 'S', long, default_value = "true")]
follow_symlinks: bool,

Expand All @@ -71,7 +71,7 @@ pub enum PluginCommand {

#[arg(short = 's', long, value_enum, default_value = "plugin-name")]
output_filename_source: FilenameSource,

#[arg(short = 'S', long, default_value = "true")]
follow_symlinks: bool,

Expand Down
65 changes: 49 additions & 16 deletions src/cli/plugin/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,25 @@ impl Deployer {
format!("deck@{}", deck.deckip),
"-p".to_string(),
format!("{}", deck.deckport),
format!("{}", if deck.deckkey.contains("-i ") { "-i" } else { "" }),
format!("{}", if deck.deckkey.contains("-i ") {
deck.deckkey
.replace("-i ", "")
.replace("$HOME", &*home_dir().unwrap().to_string_lossy())
.replace("${env:HOME}", &*home_dir().unwrap().to_string_lossy())
} else {"".to_string()}),
format!(
"{}",
if deck.deckkey.contains("-i ") {
"-i"
} else {
""
}
),
format!(
"{}",
if deck.deckkey.contains("-i ") {
deck.deckkey
.replace("-i ", "")
.replace("$HOME", &*home_dir().unwrap().to_string_lossy())
.replace("${env:HOME}", &*home_dir().unwrap().to_string_lossy())
} else {
"".to_string()
}
),
format!(
"echo '{}' | sudo -S chmod -R ug+rw {}/homebrew/",
deck.deckpass, deck.deckdir
Expand Down Expand Up @@ -104,13 +116,25 @@ impl Deployer {
format!("deck@{}", deck.deckip),
"-p".to_string(),
format!("{}", deck.deckport),
format!("{}", if deck.deckkey.contains("-i ") { "-i" } else { "" }),
format!("{}", if deck.deckkey.contains("-i ") {
deck.deckkey
.replace("-i ", "")
.replace("$HOME", &*home_dir().unwrap().to_string_lossy())
.replace("${env:HOME}", &*home_dir().unwrap().to_string_lossy())
} else {"".to_string()}),
format!(
"{}",
if deck.deckkey.contains("-i ") {
"-i"
} else {
""
}
),
format!(
"{}",
if deck.deckkey.contains("-i ") {
deck.deckkey
.replace("-i ", "")
.replace("$HOME", &*home_dir().unwrap().to_string_lossy())
.replace("${env:HOME}", &*home_dir().unwrap().to_string_lossy())
} else {
"".to_string()
}
),
format!(
"echo '{}' | sudo -S systemctl restart plugin_loader.service",
deck.deckpass
Expand Down Expand Up @@ -171,7 +195,15 @@ impl Deployer {
.to_string_lossy()
.to_string(),
};
let zip_filename = format!("{}{}.zip", &filename, if self.builder.build_with_dev { "-dev".to_string() } else { "".to_string() });
let zip_filename = format!(
"{}{}.zip",
&filename,
if self.builder.build_with_dev {
"-dev".to_string()
} else {
"".to_string()
}
);
let file = std::fs::File::open(&self.builder.output_root.join(zip_filename))
.expect("Could not open zip file");
let mut zip = zip::ZipArchive::new(file).unwrap();
Expand Down Expand Up @@ -214,7 +246,8 @@ impl Deployer {
build_with_dev,
follow_symlinks,
output_filename_source,
).expect("Could not create builder");
)
.expect("Could not create builder");

Ok(Self {
builder: builder.clone(),
Expand Down
18 changes: 13 additions & 5 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ pub async fn build_image(dockerfile: PathBuf, tag: String) -> Result<String> {
}

// docker run --rm -i -v $PWD/backend:/backend -v /tmp/output/$plugin/backend/out:/backend/out --entrypoint /backend/entrypoint.sh "$docker_name"
pub async fn run_image(tag: String, binds: Vec<(String, String)>, run_as_root: bool, run_with_dev: bool) -> Result<()> {
pub async fn run_image(
tag: String,
binds: Vec<(String, String)>,
run_as_root: bool,
run_with_dev: bool,
) -> Result<()> {
let mut cmd = Command::new("docker");
let mut command_with_default_args = cmd.arg("run").arg("--rm");

Expand All @@ -83,10 +88,13 @@ pub async fn run_image(tag: String, binds: Vec<(String, String)>, run_as_root: b
}

if run_with_dev {
command_with_default_args = command_with_default_args.arg("-e").arg("RELEASE_TYPE=development")
}
else {
command_with_default_args = command_with_default_args.arg("-e").arg("RELEASE_TYPE=production")
command_with_default_args = command_with_default_args
.arg("-e")
.arg("RELEASE_TYPE=development")
} else {
command_with_default_args = command_with_default_args
.arg("-e")
.arg("RELEASE_TYPE=production")
}

let mut dynamic_args: Vec<String> = vec![];
Expand Down
16 changes: 12 additions & 4 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,27 @@ impl Plugin {
plugin_root
.join("deck.json")
.exists()
.as_result(deckfile_location.clone(), anyhow!("Could not find deck.json"))
.as_result(
deckfile_location.clone(),
anyhow!("Could not find deck.json"),
)
.and_then(|deckfile| std::fs::read_to_string(deckfile).map_err(Into::into))
.and_then(|str| serde_json::from_str::<DeckFile>(&str).map_err(Into::into)).or_else(|_| {
.and_then(|str| serde_json::from_str::<DeckFile>(&str).map_err(Into::into))
.or_else(|_| {
let deck = DeckFile {
deckip: "0.0.0.0".to_string(),
deckport: "22".to_string(),
deckpass: "ssap".to_string(),
deckkey: "-i $HOME/.ssh/id_rsa".to_string(),
deckdir: "/home/deck".to_string(),
};
std::fs::write(deckfile_location, serde_json::to_string_pretty(&deck).unwrap()).unwrap();
std::fs::write(
deckfile_location,
serde_json::to_string_pretty(&deck).unwrap(),
)
.unwrap();
Ok(deck)
})
})
}

fn find_pluginfile(plugin_root: &Path) -> Result<PluginFile> {
Expand Down

0 comments on commit 6681f77

Please sign in to comment.