-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Added get-version feature (#248)
* feat(cli): Added get-version feature Added the read-only feature "get-version", that will output the latest version * feat(cli): Added monorepo-support to get-version command * feat(cli): Removed disable_fallback option from get-version command and adjusted tests accordingly * refactor: Made use of transitive matching for NoTag-error Co-authored-by: Marcin Puc <tranzystorek.io@protonmail.com> * style: Make clippy happy * style(cli): Corrected import order --------- Co-authored-by: André Dörscheln <ad@itesign.de> Co-authored-by: Marcin Puc <tranzystorek.io@protonmail.com>
- Loading branch information
1 parent
c2e7ab0
commit 5670cd8
Showing
22 changed files
with
348 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use anyhow::bail; | ||
use anyhow::Result; | ||
use log::warn; | ||
use semver::Version; | ||
|
||
use crate::git::error::TagError; | ||
use crate::CocoGitto; | ||
|
||
impl CocoGitto { | ||
pub fn get_latest_version( | ||
&self, | ||
fallback: Option<String>, | ||
package: Option<String>, | ||
) -> Result<()> { | ||
let fallback = match fallback { | ||
Some(input) => match Version::parse(&input) { | ||
Ok(version) => Some(version), | ||
Err(err) => { | ||
warn!("Invalid fallback: {}", input); | ||
bail!("{}", err) | ||
} | ||
}, | ||
None => None, | ||
}; | ||
|
||
let current_tag = match package { | ||
Some(pkg) => self.repository.get_latest_package_tag(&pkg), | ||
None => self.repository.get_latest_tag(), | ||
}; | ||
|
||
let current_version = match current_tag { | ||
Ok(tag) => tag.version, | ||
Err(TagError::NoTag) => match fallback { | ||
Some(input) => input, | ||
None => bail!("No version yet"), | ||
}, | ||
Err(err) => bail!("{}", err), | ||
}; | ||
|
||
warn!("Current version:"); | ||
print!("{current_version}"); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ pub mod changelog; | |
pub mod check; | ||
pub mod commit; | ||
pub mod edit; | ||
pub mod get_version; | ||
pub mod init; | ||
pub mod log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.