Skip to content

Commit aadc95f

Browse files
committed
Fix programming languages structure
1 parent 3b724a0 commit aadc95f

File tree

5 files changed

+31
-48
lines changed

5 files changed

+31
-48
lines changed

src/configs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::pipelines::DescribedPipeline;
2323
use crate::utils::{ordered_map, ordered_set};
2424
use crate::{hmap, hset};
2525

26-
const CURRENT_PROJECT_CONF_VERSION: u8 = 3;
26+
const CURRENT_PROJECT_CONF_VERSION: u8 = 4;
2727
fn get_default_project_conf_version() -> u8 {
2828
CURRENT_PROJECT_CONF_VERSION
2929
}
@@ -98,7 +98,7 @@ impl Default for DeployerProjectOptions {
9898
}
9999
}
100100

101-
const CURRENT_GLOBAL_CONF_VERSION: u8 = 3;
101+
const CURRENT_GLOBAL_CONF_VERSION: u8 = 4;
102102
fn get_default_global_conf_version() -> u8 {
103103
CURRENT_GLOBAL_CONF_VERSION
104104
}
@@ -164,7 +164,7 @@ impl Default for DeployerGlobalConfig {
164164
info,
165165
tags: vec!["rust".into(), "cargo".into()],
166166
action: Action::Build(BuildAction {
167-
supported_langs: vec![ProgrammingLanguage::Rust],
167+
supported_langs: vec![ProgrammingLanguage("rust".to_string())],
168168
commands: vec![CustomCommand {
169169
bash_c: "cargo build --release".into(),
170170
placeholders: None,

src/configs/migrate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ fn migrate_custom_v3_to_v4(prev_cmd: &CustomCommandV3) -> CustomCommand {
5353

5454
fn migrate_pls_v3_to_v4(prev_lang: &ProgrammingLanguageV3) -> ProgrammingLanguage {
5555
match prev_lang {
56-
ProgrammingLanguageV3::Rust => ProgrammingLanguage::Rust,
57-
ProgrammingLanguageV3::Go => ProgrammingLanguage::Go,
58-
ProgrammingLanguageV3::C => ProgrammingLanguage::C,
59-
ProgrammingLanguageV3::Cpp => ProgrammingLanguage::Cpp,
60-
ProgrammingLanguageV3::Python => ProgrammingLanguage::Python,
61-
ProgrammingLanguageV3::Other(v) => ProgrammingLanguage::Other(v.to_owned()),
56+
ProgrammingLanguageV3::Rust => ProgrammingLanguage("rust".to_string()),
57+
ProgrammingLanguageV3::Go => ProgrammingLanguage("go".to_string()),
58+
ProgrammingLanguageV3::C => ProgrammingLanguage("c".to_string()),
59+
ProgrammingLanguageV3::Cpp => ProgrammingLanguage("cpp".to_string()),
60+
ProgrammingLanguageV3::Python => ProgrammingLanguage("python".to_string()),
61+
ProgrammingLanguageV3::Other(v) => ProgrammingLanguage(v.to_string()),
6262
}
6363
}
6464

src/entities/programming_languages.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,11 @@ use serde::{Deserialize, Serialize};
77
/// Canonically represents most well-known by `deployer` author languages,
88
/// but you always specify yours.
99
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
10-
#[serde(rename_all = "snake_case", untagged)]
11-
pub enum ProgrammingLanguage {
12-
Rust,
13-
Go,
14-
C,
15-
Cpp,
16-
Python,
17-
Other(String),
18-
}
10+
#[serde(rename_all = "snake_case")]
11+
pub struct ProgrammingLanguage(pub String);
1912

2013
impl std::fmt::Display for ProgrammingLanguage {
2114
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22-
let lang = match self {
23-
Self::Rust => "Rust".to_string(),
24-
Self::Go => "Go".to_string(),
25-
Self::C => "C".to_string(),
26-
Self::Cpp => "C++".to_string(),
27-
Self::Python => "Python".to_string(),
28-
Self::Other(s) => s.to_owned(),
29-
};
30-
31-
f.write_str(&lang)
15+
f.write_str(&self.0)
3216
}
3317
}

src/tui/add.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ impl DeployerProjectOptions {
4646
println!("{}", i18n::PROJECT_SPECIFY_PLS);
4747
self.langs = specify_programming_languages()?;
4848
for lang in &self.langs {
49-
match lang {
50-
ProgrammingLanguage::Rust => self
49+
let ProgrammingLanguage(lang) = lang;
50+
match lang.as_str() {
51+
"rust" => self
5152
.cache_files
5253
.extend([PathBuf::from("Cargo.lock"), PathBuf::from("target")].into_iter()),
53-
ProgrammingLanguage::Go => self
54+
"go" => self
5455
.cache_files
5556
.extend([PathBuf::from("go.sum"), PathBuf::from("vendor")].into_iter()),
56-
ProgrammingLanguage::Python => self
57+
"python" => self
5758
.cache_files
5859
.extend([PathBuf::from("__pycache__"), PathBuf::from("dist")].into_iter()),
59-
ProgrammingLanguage::C | ProgrammingLanguage::Cpp => self
60+
"c" | "cpp" => self
6061
.cache_files
6162
.extend([PathBuf::from("CMakeFiles"), PathBuf::from("CMakeCache.txt")].into_iter()),
6263
_ => {}
@@ -990,12 +991,12 @@ impl ProgrammingLanguage {
990991
pub fn new_from_prompt() -> anyhow::Result<Self> {
991992
let s = inquire::Text::new(i18n::PL_INPUT_PROMPT).prompt()?;
992993
let pl = match s.as_str() {
993-
"Rust" => Self::Rust,
994-
"Go" => Self::Go,
995-
"C" => Self::C,
996-
"C++" => Self::Cpp,
997-
"Python" => Self::Python,
998-
s => Self::Other(s.to_owned()),
994+
"Rust" => Self("rust".to_string()),
995+
"Go" => Self("go".to_string()),
996+
"C" => Self("c".to_string()),
997+
"C++" => Self("cpp".to_string()),
998+
"Python" => Self("python".to_string()),
999+
s => Self(s.to_string()),
9991000
};
10001001
Ok(pl)
10011002
}
@@ -1011,11 +1012,11 @@ pub fn specify_programming_languages() -> anyhow::Result<Vec<ProgrammingLanguage
10111012
let mut result = Vec::new();
10121013
for lang in selected {
10131014
let lang = match lang {
1014-
"Rust" => ProgrammingLanguage::Rust,
1015-
"Go" => ProgrammingLanguage::Go,
1016-
"C" => ProgrammingLanguage::C,
1017-
"C++" => ProgrammingLanguage::Cpp,
1018-
"Python" => ProgrammingLanguage::Python,
1015+
"Rust" => ProgrammingLanguage("rust".to_string()),
1016+
"Go" => ProgrammingLanguage("go".to_string()),
1017+
"C" => ProgrammingLanguage("c".to_string()),
1018+
"C++" => ProgrammingLanguage("cpp".to_string()),
1019+
"Python" => ProgrammingLanguage("python".to_string()),
10191020
"Others" => {
10201021
let langs = collect_multiple_languages()?;
10211022
result.extend_from_slice(&langs);
@@ -1037,7 +1038,7 @@ fn collect_multiple_languages() -> anyhow::Result<Vec<ProgrammingLanguage>> {
10371038
for lang in langs {
10381039
match lang.as_str() {
10391040
"Rust" | "Go" | "C" | "C++" | "Python" => continue,
1040-
lang => v.push(ProgrammingLanguage::Other(lang.to_owned())),
1041+
lang => v.push(ProgrammingLanguage(lang.to_string())),
10411042
}
10421043
}
10431044

src/tui/setup.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ impl DescribedAction {
2626
let mut action = action.clone();
2727
if !langs.is_empty()
2828
&& !langs.iter().any(|l| action.supported_langs.contains(l))
29-
&& !action
30-
.supported_langs
31-
.contains(&ProgrammingLanguage::Other("any".to_string()))
29+
&& !action.supported_langs.contains(&ProgrammingLanguage("any".to_string()))
3230
&& !inquire::Confirm::new(
3331
&i18n::ACTION_COMPAT_PLS
3432
.replace("{1}", &self.info.to_str())

0 commit comments

Comments
 (0)