From f9daa6775f2f205099b07bab9b3bef5af9965ec9 Mon Sep 17 00:00:00 2001 From: Offray Date: Tue, 30 Apr 2024 16:24:52 -0500 Subject: [PATCH] Moving YQ from MiniDocs and adding Windows Scoop path. --- src/ExoRepo/YQ.class.st | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ExoRepo/YQ.class.st diff --git a/src/ExoRepo/YQ.class.st b/src/ExoRepo/YQ.class.st new file mode 100644 index 0000000..2424ca3 --- /dev/null +++ b/src/ExoRepo/YQ.class.st @@ -0,0 +1,53 @@ +" +The `External` tag is related on its dependency on other programming languages and frameworks, +though the dependency should be loaded by just loading a small binary with no dependencies. +" +Class { + #name : #YQ, + #superclass : #Object, + #category : #'ExoRepo-External' +} + +{ #category : #accessing } +YQ class >> binaryDownloadLinkFor: operativeSystem on: processor [ + | binaryName binaryDownloadData | + binaryName := 'yq_', operativeSystem , '_', processor. + binaryDownloadData := ((self lastReleaseData at: 'assets') + select: [:each | (each at: 'name') beginsWith: binaryName ]) first. + ^ binaryDownloadData at: 'browser_download_url' +] + +{ #category : #accessing } +YQ class >> binaryFile [ + "Starting with location on Arch Linux and its derivates. Multidistro and multiOS support should be added." + Smalltalk os isWindows ifFalse: [^ FileLocator root / 'usr/bin/yq']. + ^ FileLocator home / 'scoop/shims/yq.exe' +] + +{ #category : #accessing } +YQ class >> install [ + ^ self lastReleaseData +] + +{ #category : #accessing } +YQ class >> jsonToYaml: aDictionary [ + | jsonFile | + self binaryFile exists ifFalse: [ YQ install]. + jsonFile := MarkupFile exportAsFileOn: FileLocator temp / 'data.json' containing: aDictionary. + (Smalltalk os isUnix or: [ Smalltalk os isMacOS ]) + ifTrue: [ + OSSUnixSubprocess new + shellCommand: 'cat ', jsonFile fullName,' | yq -y'; + redirectStdout; + runAndWaitOnExitDo: [ :command :outString | + ^ outString + ]]. + Smalltalk os isWindows + ifTrue: [ ^ LibC resultOfCommand: 'yq -p=json ', jsonFile fullName ]. +] + +{ #category : #accessing } +YQ class >> lastReleaseData [ + ^ (STONJSON + fromString: 'https://api.github.com/repos/mikefarah/yq/releases' asUrl retrieveContents) first +]