mirror of
https://github.com/nushell/nushell.git
synced 2024-12-27 01:19:25 +01:00
Value helpers (#3000)
* Update README.md add contributors graphic * just a couple of helpers * separated some helpers out to individual fns
This commit is contained in:
parent
fa928bd25d
commit
ecaea57263
57
README.md
57
README.md
@ -50,13 +50,13 @@ To build Nu, you will need to use the **latest stable (1.47 or later)** version
|
|||||||
|
|
||||||
Required dependencies:
|
Required dependencies:
|
||||||
|
|
||||||
* pkg-config and libssl (only needed on Linux)
|
- pkg-config and libssl (only needed on Linux)
|
||||||
* On Debian/Ubuntu: `apt install pkg-config libssl-dev`
|
- On Debian/Ubuntu: `apt install pkg-config libssl-dev`
|
||||||
|
|
||||||
Optional dependencies:
|
Optional dependencies:
|
||||||
|
|
||||||
* To use Nu with all possible optional features enabled, you'll also need the following:
|
- To use Nu with all possible optional features enabled, you'll also need the following:
|
||||||
* On Linux (on Debian/Ubuntu): `apt install libxcb-composite0-dev libx11-dev`
|
- On Linux (on Debian/Ubuntu): `apt install libxcb-composite0-dev libx11-dev`
|
||||||
|
|
||||||
To install Nu via cargo (make sure you have installed [rustup](https://rustup.rs/) and the latest stable compiler via `rustup install stable`):
|
To install Nu via cargo (make sure you have installed [rustup](https://rustup.rs/) and the latest stable compiler via `rustup install stable`):
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ Just as the Unix philosophy, Nu allows commands to output from stdout and read f
|
|||||||
Additionally, commands can output structured data (you can think of this as a third kind of stream).
|
Additionally, commands can output structured data (you can think of this as a third kind of stream).
|
||||||
Commands that work in the pipeline fit into one of three categories:
|
Commands that work in the pipeline fit into one of three categories:
|
||||||
|
|
||||||
* Commands that produce a stream (eg, `ls`)
|
- Commands that produce a stream (eg, `ls`)
|
||||||
* Commands that filter a stream (eg, `where type == "Dir"`)
|
- Commands that filter a stream (eg, `where type == "Dir"`)
|
||||||
* Commands that consume the output of the pipeline (eg, `autoview`)
|
- Commands that consume the output of the pipeline (eg, `autoview`)
|
||||||
|
|
||||||
Commands are separated by the pipe symbol (`|`) to denote a pipeline flowing left to right.
|
Commands are separated by the pipe symbol (`|`) to denote a pipeline flowing left to right.
|
||||||
|
|
||||||
@ -270,15 +270,15 @@ If the plugin is a sink, it is given the full vector of final data and is given
|
|||||||
|
|
||||||
Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.
|
Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.
|
||||||
|
|
||||||
* First and foremost, Nu is cross-platform. Commands and techniques should carry between platforms and offer first-class consistent support for Windows, macOS, and Linux.
|
- First and foremost, Nu is cross-platform. Commands and techniques should carry between platforms and offer first-class consistent support for Windows, macOS, and Linux.
|
||||||
|
|
||||||
* Nu ensures direct compatibility with existing platform-specific executables that make up people's workflows.
|
- Nu ensures direct compatibility with existing platform-specific executables that make up people's workflows.
|
||||||
|
|
||||||
* Nu's workflow and tools should have the usability in day-to-day experience of using a shell in 2019 (and beyond).
|
- Nu's workflow and tools should have the usability in day-to-day experience of using a shell in 2019 (and beyond).
|
||||||
|
|
||||||
* Nu views data as both structured and unstructured. It is a structured shell like PowerShell.
|
- Nu views data as both structured and unstructured. It is a structured shell like PowerShell.
|
||||||
|
|
||||||
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.
|
- Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
@ -288,22 +288,22 @@ You can find a list of Nu commands, complete with documentation, in [quick comma
|
|||||||
|
|
||||||
Nu is in heavy development, and will naturally change as it matures and people use it. The chart below isn't meant to be exhaustive, but rather helps give an idea for some of the areas of development and their relative completion:
|
Nu is in heavy development, and will naturally change as it matures and people use it. The chart below isn't meant to be exhaustive, but rather helps give an idea for some of the areas of development and their relative completion:
|
||||||
|
|
||||||
| Features | Not started | Prototype | MVP | Preview | Mature | Notes
|
| Features | Not started | Prototype | MVP | Preview | Mature | Notes |
|
||||||
| -------- |:-----------:|:---------:|:---:|:-------:|:------:| -----
|
| ------------- | :---------: | :-------: | :-: | :-----: | :----: | -------------------------------------------------------------------- |
|
||||||
| Aliases | | X | | | | Initial implementation but lacks necessary features
|
| Aliases | | X | | | | Initial implementation but lacks necessary features |
|
||||||
| Notebook | | X | | | | Initial jupyter support, but it loses state and lacks features
|
| Notebook | | X | | | | Initial jupyter support, but it loses state and lacks features |
|
||||||
| File ops | | | X | | | cp, mv, rm, mkdir have some support, but lacking others
|
| File ops | | | X | | | cp, mv, rm, mkdir have some support, but lacking others |
|
||||||
| Environment | | X | | | | Temporary environment, but no session-wide env variables
|
| Environment | | X | | | | Temporary environment, but no session-wide env variables |
|
||||||
| Shells | | X | | | | Basic value and file shells, but no opt-in/opt-out for commands
|
| Shells | | X | | | | Basic value and file shells, but no opt-in/opt-out for commands |
|
||||||
| Protocol | | | X | | | Streaming protocol is serviceable
|
| Protocol | | | X | | | Streaming protocol is serviceable |
|
||||||
| Plugins | | X | | | | Plugins work on one row at a time, lack batching and expression eval
|
| Plugins | | X | | | | Plugins work on one row at a time, lack batching and expression eval |
|
||||||
| Errors | | | X | | | Error reporting works, but could use usability polish
|
| Errors | | | X | | | Error reporting works, but could use usability polish |
|
||||||
| Documentation | | X | | | | Book and related are barebones and lack task-based lessons
|
| Documentation | | X | | | | Book and related are barebones and lack task-based lessons |
|
||||||
| Paging | | X | | | | Textview has paging, but we'd like paging for tables
|
| Paging | | X | | | | Textview has paging, but we'd like paging for tables |
|
||||||
| Functions | | X | | | | No functions, yet, only aliases
|
| Functions | | X | | | | No functions, yet, only aliases |
|
||||||
| Variables| | X | | | | Nu doesn't yet support variables
|
| Variables | | X | | | | Nu doesn't yet support variables |
|
||||||
| Completions | | X | | | | Completions are currently barebones, at best
|
| Completions | | X | | | | Completions are currently barebones, at best |
|
||||||
| Type-checking | | X | | | | Commands check basic types, but input/output isn't checked
|
| Type-checking | | X | | | | Commands check basic types, but input/output isn't checked |
|
||||||
|
|
||||||
## Current Roadmap
|
## Current Roadmap
|
||||||
|
|
||||||
@ -318,7 +318,6 @@ Thanks to all the people who already contributed!
|
|||||||
<a href="https://github.com/nushell/nushell/graphs/contributors">
|
<a href="https://github.com/nushell/nushell/graphs/contributors">
|
||||||
<img src="https://contributors-img.web.app/image?repo=nushell/nushell" />
|
<img src="https://contributors-img.web.app/image?repo=nushell/nushell" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
The project is made available under the MIT license. See the `LICENSE` file for more information.
|
The project is made available under the MIT license. See the `LICENSE` file for more information.
|
||||||
|
@ -320,6 +320,48 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// View the Value as a FilePath (PathBuf), if possible
|
||||||
|
pub fn as_filepath(&self) -> Result<PathBuf, ShellError> {
|
||||||
|
match &self.value {
|
||||||
|
UntaggedValue::Primitive(Primitive::FilePath(path)) => Ok(path.clone()),
|
||||||
|
_ => Err(ShellError::type_error("string", self.spanned_type_name())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// View the Value as a Int (BigInt), if possible
|
||||||
|
pub fn as_int(&self) -> Result<BigInt, ShellError> {
|
||||||
|
match &self.value {
|
||||||
|
UntaggedValue::Primitive(Primitive::Int(n)) => Ok(n.clone()),
|
||||||
|
_ => Err(ShellError::type_error("bigint", self.spanned_type_name())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// View the Value as a Filesize (BigInt), if possible
|
||||||
|
pub fn as_filesize(&self) -> Result<BigInt, ShellError> {
|
||||||
|
match &self.value {
|
||||||
|
UntaggedValue::Primitive(Primitive::Filesize(fs)) => Ok(fs.clone()),
|
||||||
|
_ => Err(ShellError::type_error("bigint", self.spanned_type_name())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// View the Value as a Duration (BigInt), if possible
|
||||||
|
pub fn as_duration(&self) -> Result<BigInt, ShellError> {
|
||||||
|
match &self.value {
|
||||||
|
UntaggedValue::Primitive(Primitive::Duration(dur)) => Ok(dur.clone()),
|
||||||
|
_ => Err(ShellError::type_error("bigint", self.spanned_type_name())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// View the Value as a Decimal (BigDecimal), if possible
|
||||||
|
pub fn as_decimal(&self) -> Result<BigDecimal, ShellError> {
|
||||||
|
match &self.value {
|
||||||
|
UntaggedValue::Primitive(Primitive::Decimal(d)) => Ok(d.clone()),
|
||||||
|
_ => Err(ShellError::type_error(
|
||||||
|
"bigdecimal",
|
||||||
|
self.spanned_type_name(),
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn convert_to_string(&self) -> String {
|
pub fn convert_to_string(&self) -> String {
|
||||||
match &self.value {
|
match &self.value {
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => s.clone(),
|
UntaggedValue::Primitive(Primitive::String(s)) => s.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user