diff --git a/docs/en/src/upgrade-guide.md b/docs/en/src/upgrade-guide.md index 40a3676..f78a87f 100644 --- a/docs/en/src/upgrade-guide.md +++ b/docs/en/src/upgrade-guide.md @@ -32,13 +32,13 @@ Knowing that we use the `{major}.{minor}.{patch}` versioning format, e.g. -- `1.0.0` -> `1.0.x`: Bug fix (fully compatible). +- `1.0.0` -> `1.0.x`: Patch (fully compatible). - `1.0.0` -> `1.x.x`: Only backwards compatible. You can't generally use for e.g. `app-1.0.0` with `config-1.1.0`. But vice versa is fine. - `1.0.0` -> `x.x.x`: Not compatible at all. Note that until we're `v1`, we'll be using the `{minor}` version number as -`{major}`, and the `{patch}` fix number as `{minor}` to determine +`{major}`, and the `{patch}` number as `{minor}` to determine compatibility. diff --git a/docs/en/src/xplr.util.md b/docs/en/src/xplr.util.md index a6ee65d..9243ff0 100644 --- a/docs/en/src/xplr.util.md +++ b/docs/en/src/xplr.util.md @@ -1,3 +1,16 @@ +### xplr.util.version + +Get the current xplr version details. + +Type: function() -> { major: number, minor: number, patch: number } + +Example: + +```lua +xplr.util.version() +-- { major = 0, minor = 0, patch = 0 } +``` + ### xplr.util.dirname Get the directory name of a given path. diff --git a/src/lua/mod.rs b/src/lua/mod.rs index d0ba436..e1e8be4 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -29,15 +29,15 @@ fn parse_version(version: &str) -> Result<(u16, u16, u16, Option)> { let major = configv.next().unwrap_or_default().parse::()?; let minor = configv.next().unwrap_or_default().parse::()?; - let bugfix = configv + let patch = configv .next() .and_then(|s| s.split('-').next()) .unwrap_or_default() .parse::()?; - let beta = configv.next().unwrap_or_default().parse::().ok(); + let pre = configv.next().unwrap_or_default().parse::().ok(); - Ok((major, minor, bugfix, beta)) + Ok((major, minor, patch, pre)) } /// Check the config version and notify users. diff --git a/src/lua/util.rs b/src/lua/util.rs index 8993229..dd5940c 100644 --- a/src/lua/util.rs +++ b/src/lua/util.rs @@ -1,3 +1,4 @@ +use crate::app::VERSION; use crate::explorer; use crate::lua; use crate::msg::in_::external::ExplorerConfig; @@ -18,6 +19,7 @@ use std::process::Command; pub(crate) fn create_table(lua: &Lua) -> Result { let mut util = lua.create_table()?; + util = version(util, lua)?; util = dirname(util, lua)?; util = basename(util, lua)?; util = absolute(util, lua)?; @@ -32,6 +34,42 @@ pub(crate) fn create_table(lua: &Lua) -> Result
{ Ok(util) } +/// Get the xplr version details. +/// +/// Type: function() -> { major: number, minor: number, patch: number } +/// +/// Example: +/// +/// ```lua +/// xplr.util.version() +/// -- { major = 0, minor = 0, patch = 0 } +/// ``` +pub fn version<'a>(util: Table<'a>, lua: &Lua) -> Result> { + #[derive(Debug, Default, Serialize, Deserialize)] + struct Version { + major: u16, + minor: u16, + patch: u16, + } + + let func = lua.create_function(|lua, ()| { + let (major, minor, patch, _) = + lua::parse_version(VERSION).map_err(LuaError::custom)?; + + let version = Version { + major, + minor, + patch, + }; + + let res = lua::serialize(lua, &version).map_err(LuaError::custom)?; + Ok(res) + })?; + + util.set("version", func)?; + Ok(util) +} + /// Get the directory name of a given path. /// /// Type: function( path:string ) -> path:string|nil @@ -215,8 +253,8 @@ pub fn from_json<'a>(util: Table<'a>, lua: &Lua) -> Result> { /// -- }]] /// ``` pub fn to_json<'a>(util: Table<'a>, lua: &Lua) -> Result> { - #[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)] - pub struct Options { + #[derive(Debug, Default, Serialize, Deserialize)] + struct Options { pretty: bool, }