feat: with start of environment engine
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
5876ed847c
commit
1b9f8b26e6
@ -10,6 +10,7 @@ use clap::{Args, Parser, Subcommand};
|
|||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
environment::get_from_environment,
|
||||||
git_client::VcsClient,
|
git_client::VcsClient,
|
||||||
gitea_client::GiteaClient,
|
gitea_client::GiteaClient,
|
||||||
ui::{ConsoleUi, DynUi},
|
ui::{ConsoleUi, DynUi},
|
||||||
@ -132,7 +133,9 @@ impl Command {
|
|||||||
current_dir: &Path,
|
current_dir: &Path,
|
||||||
stdin: Option<String>,
|
stdin: Option<String>,
|
||||||
) -> anyhow::Result<PleaseConfig> {
|
) -> anyhow::Result<PleaseConfig> {
|
||||||
let config = get_config(current_dir, stdin)?;
|
let mut config = get_config(current_dir, stdin)?;
|
||||||
|
|
||||||
|
self.get_from_environment(&mut config)?;
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
@ -212,6 +215,13 @@ impl Command {
|
|||||||
VcsClient::new_git(current_dir)
|
VcsClient::new_git(current_dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_from_environment(&self, config: &mut PleaseConfig) -> anyhow::Result<()> {
|
||||||
|
let input_config = get_from_environment();
|
||||||
|
config.merge_mut(input_config);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
@ -257,17 +267,38 @@ fn get_current_path(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
struct PleaseConfig {}
|
pub struct PleaseProjectConfig {
|
||||||
|
pub owner: Option<String>,
|
||||||
|
pub repository: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct PleaseSettingsConfig {
|
||||||
|
pub api_url: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct PleaseConfig {
|
||||||
|
pub project: Option<PleaseProjectConfig>,
|
||||||
|
pub settings: Option<PleaseSettingsConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
impl PleaseConfig {
|
impl PleaseConfig {
|
||||||
fn merge(self, _config: PleaseConfig) -> Self {
|
fn merge(self, _config: PleaseConfig) -> Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn merge_mut(&mut self, _config: PleaseConfig) -> &mut Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PleaseConfig {
|
impl Default for PleaseConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {}
|
Self {
|
||||||
|
project: None,
|
||||||
|
settings: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
crates/cuddle-please/src/environment/drone.rs
Normal file
1
crates/cuddle-please/src/environment/drone.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
38
crates/cuddle-please/src/environment/mod.rs
Normal file
38
crates/cuddle-please/src/environment/mod.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use crate::command::{PleaseConfig, PleaseProjectConfig, PleaseSettingsConfig};
|
||||||
|
|
||||||
|
pub mod drone;
|
||||||
|
|
||||||
|
pub fn get_from_environment() -> PleaseConfig {
|
||||||
|
let env = detect_environment();
|
||||||
|
|
||||||
|
match env {
|
||||||
|
ExecutionEnvironment::Local => PleaseConfig {
|
||||||
|
project: None,
|
||||||
|
settings: None,
|
||||||
|
},
|
||||||
|
ExecutionEnvironment::Drone => PleaseConfig {
|
||||||
|
project: Some(PleaseProjectConfig {
|
||||||
|
owner: Some(
|
||||||
|
std::env::var("DRONE_REPO_OWNER").expect("DRONE_REPO_OWNER to be present"),
|
||||||
|
),
|
||||||
|
repository: Some(
|
||||||
|
std::env::var("DRONE_REPO_NAME").expect("DRONE_REPO_NAME to be present"),
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
settings: None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn detect_environment() -> ExecutionEnvironment {
|
||||||
|
if let Some(_) = std::env::var("DRONE").ok() {
|
||||||
|
return ExecutionEnvironment::Drone;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExecutionEnvironment::Local;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ExecutionEnvironment {
|
||||||
|
Local,
|
||||||
|
Drone,
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
pub mod command;
|
pub mod command;
|
||||||
|
pub mod environment;
|
||||||
pub mod git_client;
|
pub mod git_client;
|
||||||
pub mod gitea_client;
|
pub mod gitea_client;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub mod command;
|
pub mod command;
|
||||||
|
pub mod environment;
|
||||||
pub mod git_client;
|
pub mod git_client;
|
||||||
pub mod gitea_client;
|
pub mod gitea_client;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
Loading…
Reference in New Issue
Block a user