Implement xplr.util.version

Closes: https://github.com/sayanarijit/xplr/issues/540
pull/549/head
Arijit Basu 1 year ago committed by Arijit Basu
parent d4edf3302f
commit e559b96e31

@ -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.
</details>

@ -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.

@ -29,15 +29,15 @@ fn parse_version(version: &str) -> Result<(u16, u16, u16, Option<u16>)> {
let major = configv.next().unwrap_or_default().parse::<u16>()?;
let minor = configv.next().unwrap_or_default().parse::<u16>()?;
let bugfix = configv
let patch = configv
.next()
.and_then(|s| s.split('-').next())
.unwrap_or_default()
.parse::<u16>()?;
let beta = configv.next().unwrap_or_default().parse::<u16>().ok();
let pre = configv.next().unwrap_or_default().parse::<u16>().ok();
Ok((major, minor, bugfix, beta))
Ok((major, minor, patch, pre))
}
/// Check the config version and notify users.

@ -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<Table> {
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<Table> {
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<Table<'a>> {
#[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<Table<'a>> {
/// -- }]]
/// ```
pub fn to_json<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Options {
#[derive(Debug, Default, Serialize, Deserialize)]
struct Options {
pretty: bool,
}

Loading…
Cancel
Save