feat: Enable to display language version when .<lang>-version file exists. (#1028)

* adjust https://github.com/sonnym/elmenv

* adjust https://github.com/syndbg/goenv

* adjust https://github.com/jenv/jenv

* adjust https://github.com/nodenv/nodenv

* adjust https://github.com/phpenv/phpenv

* adjust https://github.com/rbenv/rbenv

* add description

* golang.rs is executed rustfmt

* add testcases
This commit is contained in:
Shu Kutsuzawa 2020-04-04 04:02:28 +09:00 committed by GitHub
parent e38be5073f
commit bd016b6ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 11 deletions

View File

@ -470,6 +470,7 @@ The module will be shown if any of the following conditions are met:
- The current directory contains a `elm.json` file
- The current directory contains a `elm-package.json` file
- The current directory contains a `.elm-version` file
- The current directory contains a `elm-stuff` folder
- The current directory contains a `*.elm` files
@ -672,6 +673,7 @@ The module will be shown if any of the following conditions are met:
- The current directory contains a `glide.yaml` file
- The current directory contains a `Gopkg.yml` file
- The current directory contains a `Gopkg.lock` file
- The current directory contains a `.go-version` file
- The current directory contains a `Godeps` directory
- The current directory contains a file with the `.go` extension
@ -749,7 +751,7 @@ disabled = false
The `java` module shows the currently installed version of Java.
The module will be shown if any of the following conditions are met:
- The current directory contains a `pom.xml`, `build.gradle.kts` or `build.sbt` file
- The current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt` or `.java-version` file
- The current directory contains a file with the `.java`, `.class`, `.gradle` or `.jar` extension
### Options
@ -973,6 +975,7 @@ The `nodejs` module shows the currently installed version of NodeJS.
The module will be shown if any of the following conditions are met:
- The current directory contains a `package.json` file
- The current directory contains a `.node-version` file
- The current directory contains a `node_modules` directory
- The current directory contains a file with the `.js` extension
@ -1036,6 +1039,7 @@ The `php` module shows the currently installed version of PHP.
The module will be shown if any of the following conditions are met:
- The current directory contains a `composer.json` file
- The current directory contains a `.php-version` file
- The current directory contains a `.php` file
### Options
@ -1102,6 +1106,7 @@ The `ruby` module shows the currently installed version of Ruby.
The module will be shown if any of the following conditions are met:
- The current directory contains a `Gemfile` file
- The current directory contains a `.ruby-version` file
- The current directory contains a `.rb` file
### Options

View File

@ -8,12 +8,13 @@ use crate::utils;
/// Will display the Elm version if any of the following criteria are met:
/// - The current directory contains a `elm.json` file
/// - The current directory contains a `elm-package.json` file
/// - The current directory contains a `.elm-version` file
/// - The current directory contains a `elm-stuff` folder
/// - The current directory contains a `*.elm` files
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_elm_project = context
.try_begin_scan()?
.set_files(&["elm.json", "elm-package.json"])
.set_files(&["elm.json", "elm-package.json", ".elm-version"])
.set_extensions(&["elm"])
.set_folders(&["elm-stuff"])
.is_match();
@ -72,6 +73,16 @@ mod tests {
dir.close()
}
#[test]
fn folder_with_elm_version() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".elm-version"))?.sync_all()?;
let actual = render_module("elm", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn folder_with_elm_stuff_directory() -> io::Result<()> {
let dir = tempfile::tempdir()?;

View File

@ -11,12 +11,20 @@ use crate::utils;
/// - Current directory contains a `glide.yaml` file
/// - Current directory contains a `Gopkg.yml` file
/// - Current directory contains a `Gopkg.lock` file
/// - Current directory contains a `.go-version` file
/// - Current directory contains a `Godeps` directory
/// - Current directory contains a file with the `.go` extension
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_go_project = context
.try_begin_scan()?
.set_files(&["go.mod", "go.sum", "glide.yaml", "Gopkg.yml", "Gopkg.lock"])
.set_files(&[
"go.mod",
"go.sum",
"glide.yaml",
"Gopkg.yml",
"Gopkg.lock",
".go-version",
])
.set_extensions(&["go"])
.set_folders(&["Godeps"])
.is_match();
@ -157,6 +165,16 @@ mod tests {
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn folder_with_go_version() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".go-version"))?.sync_all()?;
let actual = render_module("golang", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn test_format_go_version() {

View File

@ -9,11 +9,11 @@ use crate::utils;
///
/// Will display the Java version if any of the following criteria are met:
/// - Current directory contains a file with a `.java`, `.class`, `.gradle` or `.jar` extension
/// - Current directory contains a `pom.xml`, `build.gradle.kts` or `build.sbt` file
/// - Current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt` or `.java-version` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_java_project = context
.try_begin_scan()?
.set_files(&["pom.xml", "build.gradle.kts", "build.sbt"])
.set_files(&["pom.xml", "build.gradle.kts", "build.sbt", ".java-version"])
.set_extensions(&["java", "class", "jar", "gradle"])
.is_match();

View File

@ -7,12 +7,12 @@ use crate::utils;
///
/// Will display the Node.js version if any of the following criteria are met:
/// - Current directory contains a `.js` file
/// - Current directory contains a `package.json` file
/// - Current directory contains a `package.json` or `.node-version` file
/// - Current directory contains a `node_modules` directory
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_js_project = context
.try_begin_scan()?
.set_files(&["package.json"])
.set_files(&["package.json", ".node-version"])
.set_extensions(&["js"])
.set_folders(&["node_modules"])
.is_match();
@ -63,6 +63,17 @@ mod tests {
dir.close()
}
#[test]
fn folder_with_node_version() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".node-version"))?.sync_all()?;
let actual = render_module("nodejs", dir.path());
let expected = Some(format!("via {} ", Color::Green.bold().paint("⬢ v12.0.0")));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn folder_with_js_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;

View File

@ -7,11 +7,11 @@ use crate::utils;
///
/// Will display the PHP version if any of the following criteria are met:
/// - Current directory contains a `.php` file
/// - Current directory contains a `composer.json` file
/// - Current directory contains a `composer.json` or `.php-version` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_php_project = context
.try_begin_scan()?
.set_files(&["composer.json"])
.set_files(&["composer.json", ".php-version"])
.set_extensions(&["php"])
.is_match();
@ -92,6 +92,21 @@ mod tests {
dir.close()
}
#[test]
fn folder_with_php_version() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".php-version"))?.sync_all()?;
let actual = render_module("php", dir.path());
let expected = Some(format!(
"via {} ",
Color::Fixed(147).bold().paint("🐘 v7.3.8")
));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn folder_with_php_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;

View File

@ -7,11 +7,11 @@ use crate::utils;
///
/// Will display the Ruby version if any of the following criteria are met:
/// - Current directory contains a `.rb` file
/// - Current directory contains a `Gemfile` file
/// - Current directory contains a `Gemfile` or `.ruby-version` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_rb_project = context
.try_begin_scan()?
.set_files(&["Gemfile"])
.set_files(&["Gemfile", ".ruby-version"])
.set_extensions(&["rb"])
.is_match();
@ -78,6 +78,18 @@ mod tests {
dir.close()
}
#[test]
fn folder_with_ruby_version() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".ruby-version"))?.sync_all()?;
let actual = render_module("ruby", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("💎 v2.5.1")));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn folder_with_rb_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;