Skip to content

Commit

Permalink
feat(scoop-cat): Use bat to pretty-print JSON (ScoopInstaller#4742)
Browse files Browse the repository at this point in the history
* feat(scoop-cat): Use `bat` to pretty-print JSON

* update changelog

* hide filename and line numbers

* Add `cat_style` config option

* use underscores

* Revert "use underscores"

This reverts commit 46524fc.

* Apply suggestions from code review

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
rashil2000 and niheaven authored Feb 17, 2022
1 parent d1f828c commit e1f569b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **scoop-list:** Allow list manipulation ([#4718](https://github.com/ScoopInstaller/Scoop/issues/4718))
- **scoop-list:** Show last-updated time [#4723](https://github.com/ScoopInstaller/Scoop/issues/4723))
- **scoop-cache:** Handle multiple apps and show detailed information ([#4738](https://github.com/ScoopInstaller/Scoop/pull/4738))
- **scoop-cat:** Use `bat` to pretty-print JSON ([#4742](https://github.com/ScoopInstaller/Scoop/pull/4742))

### Bug Fixes

Expand Down
15 changes: 10 additions & 5 deletions lib/install.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
. "$psscriptroot/autoupdate.ps1"
. "$psscriptroot/buckets.ps1"
. "$PSScriptRoot/autoupdate.ps1"
. "$PSScriptRoot/buckets.ps1"

function nightly_version($date, $quiet = $false) {
$date_str = $date.tostring("yyyyMMdd")
Expand Down Expand Up @@ -34,9 +34,14 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
return
}

if ((get_config 'manifest-review' $false) -and ($MyInvocation.ScriptName -notlike '*scoop-update*')) {
Write-Output "Manifest: $app.json"
Write-Output $manifest | ConvertToPrettyJson
if ((get_config 'manifest_review' $false) -and ($MyInvocation.ScriptName -notlike '*scoop-update*')) {
Write-Host "Manifest: $app.json"
$style = get_config cat_style
if ($style) {
$manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json
} else {
$manifest | ConvertToPrettyJson
}
$answer = Read-Host -Prompt "Continue installation? [Y/n]"
if (($answer -eq 'n') -or ($answer -eq 'N')) {
return
Expand Down
15 changes: 10 additions & 5 deletions libexec/scoop-cat.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Usage: scoop cat <app>
# Summary: Show content of specified manifest.
# Summary: Show content of specified manifest. If available, `bat` will be used to pretty-print the JSON.

param($app)

. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
. "$PSScriptRoot\..\lib\help.ps1"

reset_aliases

Expand All @@ -15,7 +15,12 @@ $app, $bucket, $null = parse_app $app
$app, $manifest, $bucket, $url = Find-Manifest $app $bucket

if ($manifest) {
$manifest | ConvertToPrettyJson | Write-Host
$style = get_config cat_style
if ($style) {
$manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json
} else {
$manifest | ConvertToPrettyJson
}
} else {
abort "Couldn't find manifest for '$app'$(if($url) { " at the URL $url" })."
}
Expand Down
6 changes: 6 additions & 0 deletions libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
# API key used for uploading/scanning files using virustotal.
# See: 'https://support.virustotal.com/hc/en-us/articles/115002088769-Please-give-me-an-API-key'
#
# cat_style:
# When set to a non-empty string, Scoop will use 'bat' to display the manifest for
# the `scoop cat` command and while doing manifest review. This requires 'bat' to be
# installed (run `scoop install bat` to install it), otherwise errors will be thrown.
# The accepted values are the same as ones passed to the --style flag of 'bat'.
#
# ignore_running_processes: $true|$false
# When set to $false (default), Scoop would stop its procedure immediately if it detects
# any target app process is running. Procedure here refers to reset/uninstall/update.
Expand Down

0 comments on commit e1f569b

Please sign in to comment.