mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-05-06 00:36:35 +00:00
add jq
This commit is contained in:
114
jq/README.md
Normal file
114
jq/README.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
title: jq
|
||||
homepage: https://stedolan.github.io/jq/
|
||||
tagline: |
|
||||
jq is a lightweight and flexible command-line JSON processor.
|
||||
description: |
|
||||
`jq` is like `sed` for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that `sed`, `awk`, `grep` and friends let you play with text.
|
||||
---
|
||||
|
||||
All jq selectors begin with `.` - don't forget that!
|
||||
|
||||
Be sure to checkout the
|
||||
[official tutorial](https://stedolan.github.io/jq/tutorial/) and
|
||||
[jq manual](https://stedolan.github.io/jq/manual/) for more info.
|
||||
|
||||
You can also [try online](https://jqplay.org/).
|
||||
|
||||
### How to select a single a property from an object
|
||||
|
||||
```bash
|
||||
echo '{ "name": "foo" }' | jq '.name'
|
||||
```
|
||||
|
||||
```txt
|
||||
"foo"
|
||||
```
|
||||
|
||||
### How to remove quotes from strings
|
||||
|
||||
The `-r` or `--raw-output` flag unwraps strings:
|
||||
|
||||
```bash
|
||||
echo '{ "name": "foo" }' | jq -r '.name'
|
||||
```
|
||||
|
||||
```txt
|
||||
"foo"
|
||||
```
|
||||
|
||||
### How to select a whole object
|
||||
|
||||
```bash
|
||||
echo '{ "name": "foo" }' | jq '.'
|
||||
```
|
||||
|
||||
```txt
|
||||
{
|
||||
"name": "foo"
|
||||
}
|
||||
```
|
||||
|
||||
### How to select an element from an array
|
||||
|
||||
```bash
|
||||
echo '[ { "name": "foo" } ]' | jq '.[0]'
|
||||
```
|
||||
|
||||
```txt
|
||||
{
|
||||
"name": "foo"
|
||||
}
|
||||
```
|
||||
|
||||
### How to select a single property from an array element
|
||||
|
||||
```bash
|
||||
echo '[ { "name": "foo" } ]' | jq -r '.[0].name'
|
||||
```
|
||||
|
||||
```txt
|
||||
foo
|
||||
```
|
||||
|
||||
### How to select some properties from multiple elements
|
||||
|
||||
```bash
|
||||
echo '[ { "name": "foo" }, { "name": "bar" } ]' \
|
||||
| jq -r '.[].name'
|
||||
```
|
||||
|
||||
```txt
|
||||
foo
|
||||
bar
|
||||
```
|
||||
|
||||
### How transform or zip an array
|
||||
|
||||
Anything that doesn't start with a `.` is part of the transformation template.
|
||||
|
||||
Anything that collects starts with `.[]`.
|
||||
|
||||
Anything that transforms has a pipe and selector `| .whatever`.
|
||||
|
||||
Be sure to checkout the
|
||||
[official tutorial](https://stedolan.github.io/jq/tutorial/) and
|
||||
[jq manual](https://stedolan.github.io/jq/manual/) for more info.
|
||||
|
||||
```bash
|
||||
echo '[ { "name": "foo", "age": 0 }, { "name": "bar", "age": 2 } ]' \
|
||||
| jq '{ names: [.[] | .name], ages: [.[] | .age] }'
|
||||
```
|
||||
|
||||
```txt
|
||||
{
|
||||
"names": [
|
||||
"foo",
|
||||
"bar"
|
||||
],
|
||||
"ages": [
|
||||
0,
|
||||
2
|
||||
]
|
||||
}
|
||||
```
|
||||
41
jq/install.ps1
Normal file
41
jq/install.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
$VERNAME = "$Env:PKG_NAME-v$Env:WEBI_VERSION.exe"
|
||||
$EXENAME = "$Env:PKG_NAME.exe"
|
||||
# Fetch archive
|
||||
IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
|
||||
{
|
||||
# TODO: arch detection
|
||||
echo "Downloading $Env:PKG_NAME from $Env:WEBI_PKG_URL to $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
|
||||
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part"
|
||||
& move "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part" "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
|
||||
}
|
||||
|
||||
IF (!(Test-Path -Path "$Env:USERPROFILE\.local\xbin\$VERNAME"))
|
||||
{
|
||||
echo "Installing $Env:PKG_NAME"
|
||||
# TODO: temp directory
|
||||
|
||||
# Enter tmp
|
||||
pushd .local\tmp
|
||||
|
||||
# Remove any leftover tmp cruft
|
||||
Remove-Item -Path "$Env:PKG_NAME-v*" -Recurse -ErrorAction Ignore
|
||||
|
||||
# Move single binary into temporary folder
|
||||
echo "Moving $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
|
||||
& move "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" "$VERNAME"
|
||||
|
||||
# Settle unpacked archive into place
|
||||
echo "New Name: $VERNAME"
|
||||
Get-ChildItem "$Env:PKG_NAME-v*" | Select -f 1 | Rename-Item -NewName "$VERNAME"
|
||||
echo "New Location: $Env:USERPROFILE\.local\xbin\$VERNAME"
|
||||
Move-Item -Path "$VERNAME" -Destination "$Env:USERPROFILE\.local\xbin"
|
||||
|
||||
# Exit tmp
|
||||
popd
|
||||
}
|
||||
|
||||
echo "Copying into '$Env:USERPROFILE\.local\bin\$EXENAME' from '$Env:USERPROFILE\.local\xbin\$VERNAME'"
|
||||
Remove-Item -Path "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse -ErrorAction Ignore
|
||||
Copy-Item -Path "$Env:USERPROFILE\.local\xbin\$VERNAME" -Destination "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse
|
||||
18
jq/install.sh
Normal file
18
jq/install.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
set -e
|
||||
set -u
|
||||
|
||||
##############
|
||||
# Install jq #
|
||||
##############
|
||||
|
||||
WEBI_SINGLE=true
|
||||
|
||||
pkg_get_current_version() {
|
||||
# 'jq --version' has output in this format:
|
||||
# jq-1.6
|
||||
# This trims it down to just the version number:
|
||||
# 1.6
|
||||
echo $(jq --version 2>/dev/null | head -n 1 | sed 's:^jq-::')
|
||||
}
|
||||
}
|
||||
23
jq/releases.js
Normal file
23
jq/releases.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var github = require('../_common/github.js');
|
||||
var owner = 'stedolan';
|
||||
var repo = 'jq';
|
||||
|
||||
module.exports = function (request) {
|
||||
return github(request, owner, repo).then(function (all) {
|
||||
all.releases.forEach(function (rel) {
|
||||
console.log(rel.version);
|
||||
rel.version = String(rel.version).replace(/^jq\-/, '');
|
||||
});
|
||||
return all;
|
||||
});
|
||||
};
|
||||
|
||||
if (module === require.main) {
|
||||
module.exports(require('@root/request')).then(function (all) {
|
||||
all = require('../_webi/normalize.js')(all);
|
||||
console.info(JSON.stringify(all));
|
||||
//console.info(JSON.stringify(all, null, 2));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user