Replies: 20 comments 2 replies
-
I think because JSON is agnostic. For example, I'm full-on interested in writing native commands from Linux, and IntelliSense doesn't make sense when I'm trying to write wrappers for commands like ip, apt, sysctl, service, uname, etc. |
Beta Was this translation helpful? Give feedback.
-
Not entirely sure what you mean by that. Crescendo files are meant for use by PowerShell, so being agnostic isn't relevant. |
Beta Was this translation helpful? Give feedback.
-
#28 this discussion is probably a better place to continue this. |
Beta Was this translation helpful? Give feedback.
-
I do think the .psd1 idea makes sense. Another possible compromise/solution idea— split the “code” parts of the json config out into dedicated files. Example json: {
"$schema": "./Microsoft.PowerShell.Crescendo.Schema.json",
"Verb": "Get",
"Noun":"InstalledPackage",
"OriginalName": "apt",
"OriginalCommandElements": ["-q","list","--installed"],
"OutputHandlers": [
{
"ParameterSetName":"Default",
"Handler": "invoke-customhandler.ps1”
}
]
} Then the ps1 file has the actual PowerShell handler code in it. You get the benefits of syntax highlighting and static analysis for the ps1 files. You also get a nice clean json file that just has config options in it that fit with your schema (in case the config itself needs to be deserialized to a specific type) |
Beta Was this translation helpful? Give feedback.
-
Config files as I'm not saying An easy-ish solution imo is a DSL to generate the json (or to generate the final product). |
Beta Was this translation helpful? Give feedback.
-
Looking in particular at the second example in the announcement I also think that this choice is really odd. While the PowerShell code was limited to a single (albeit long) line in the first example, the second includes a fair amount of code. And having that within JSON is really troublesome for various reasons:
I feel like this could have been solved in a nicer way directly within PowerShell, utilizing existing PowerShell tooling instead of relying on impractical a data format. There could have been a separate DSL, or just a chain of PowerShell commands within a ps1-file that configure the module. Something like this maybe: $module = New-CrescendoModule -Verb Get -Noun IpConfig `
-OriginalName "c:/windows/system32/ipconfig.exe" `
-Description "This will display the current IP configuration information on Windows"
Add-CrescendoParameter $module -Name All -OriginalName "/all" -ParameterType Switch `
-Description "This switch provides all ip configuration details"
Add-CrescendoParameter $module -Name AllCompartments -OriginalName "/allcompartments" -ParameterType Switch `
-Description "This switch provides compartment configuration details"
Add-CrescendoOutputHandler $module -ParameterSetName Default -Handler {
param ( $lines )
$post = $false;
foreach($line in $lines | ?{$_.trim()}) {
$LineToCheck = $line | select-string '^[a-z]';
if ( $LineToCheck ) {
if ( $post ) { [pscustomobject]$ht |add-member -pass -typename $oName }
$oName = ($LineToCheck -match 'Configuration') ? 'IpConfiguration' : 'EthernetAdapter';
$ht = @{};
$post = $true
}
else {
if ( $line -match '^ [a-z]' ) {
$prop,$value = $line.split(' :',2);
$pName = $prop -replace '[ .-]';
$ht[$pName] = $value.Trim()
}
else {
$ht[$pName] = .{$ht[$pName];$line.trim()}
}
}
}
[pscustomobject]$ht | add-member -pass -typename $oName
}
Export-CrescendoModule $module -ModuleName Ipconfig.psm1 As you can already see here, this already would have working syntax highlighting and with appropriately defined cmdlets, all those commands would offer full code completion for the various parameters – in all environments that support PowerShell without having to rely on a JSON schema to enable tooling. Since Crescendo is still in early preview, maybe changing the format could be considered. |
Beta Was this translation helpful? Give feedback.
-
JSON was chosen because we needed to schematize the file to assist authors in writing them. PSD1 don't support this at this time. We continue to be open to ideas, including revisiting PSD1. Can we agree that XML can be left of the list? |
Beta Was this translation helpful? Give feedback.
-
@theJasonHelmick Why JSON specifically, though? As the above comment points out, even your examples are invalid JSON. YAML or TOML are more appropriate configuration languages (and YAML supports JSON schema as a plus).
Yes, please. |
Beta Was this translation helpful? Give feedback.
-
While a schema certainly is a benefit, as a Crescendo file author I feel I would get much more out of not having to fight with quoting, lack of syntax highlighting, lack of IntelliSense, etc. than having a schema. |
Beta Was this translation helpful? Give feedback.
-
I couldn't agree more with @jcotton42 in every word! Besides, as I can understand from @theJasonHelmick announcement, the very purpose and origin of this framework is to make any Powershell user/fanatic feel more comfortable using the tools, syntax and format we are used to. IMHO, @poke 's approach (#27 (comment)) is much more PowerShell-ish and respectful of the "sacred vow". Thinking about JEA, it came to my mind the gap still there in JEA for native and third-party commands and how this Cresendo Framework could fill-it that gap! That last paragraph are just still-blurred ideas I'm hoping people a lot smarter than me could catch and bring to the reality. - A PowerShell User / Fanatic |
Beta Was this translation helpful? Give feedback.
-
There's also no native way to sign the JSON files using Set-AuthenticodeSignature, which for me means dumping json to psd1, signing, then re/de-serializing the JSON when I need to use it again. |
Beta Was this translation helpful? Give feedback.
-
Just chipping in for team JSON here. I have already started experimenting with automatically creating Crescendo JSON definition files from cobra (https://github.com/spf13/cobra) commands. I would have no idea how to do that if I had to create psd1 files, because no library exists for those to my knowledge. |
Beta Was this translation helpful? Give feedback.
-
JSON is objectively a bad choice:
The most obvious alternative is YAML. It solves all of these problems except powershell syntax highlighting/intellisense, so with that said I cannot fathom how YAML wasn't chosen over JSON - it's much better in every way, has no disadvantage and is already used to great success by GitHub Actions to define multi-line PowerShell scripts inside of properties/nested structures I am also open to psd1 of course - but I und erstand that doesn't support schemas yet. Either way it should be clear JSON was objectively the wrong choice and needs to go. |
Beta Was this translation helpful? Give feedback.
-
I've been watching comments trickle in here, and I have to admit I have tipped in favor of abstracting any powershell code out of the json object. I like the suggestion @keithbabinec put forth, splitting the contents between the json scaffolding, and the code references. Static analysis, tests, signatures, revision control granularity, all the benefits of native intellisense and all that hoohah - all good things. |
Beta Was this translation helpful? Give feedback.
-
You make some good points and I agree that YAML would indeed be a workable format with many advantages and it does have a broad library support (funnily enough, there are still no ConvertFrom/To-YAML commandlets available, however: PowerShell/PowerShell#3607) |
Beta Was this translation helpful? Give feedback.
-
@jantari I agree, but after more thought, I don't think YAML is an appropriate solution either due to the lack of support in the standard libraries, but also for the complex parsing and vulnerabilities that have come up in the spec. TOML took a while for me to grow to, but it also supports JSON schemas, multiline values, and all that jazz, without the complexity of parsing from YAML. |
Beta Was this translation helpful? Give feedback.
-
@theJasonHelmick Are we really validating the schema as of now ? I cant see any schema validation. |
Beta Was this translation helpful? Give feedback.
-
@kvprasoon - yes - I'm not sure what preview you were on, but give preview.3 a try |
Beta Was this translation helpful? Give feedback.
-
@Halkcyon - I would add to me previous comment that JSON is a simple intermediate that we are also using moving to for things like DSC. I'm not arguing that it is better/worse than YAML or , but it is a simple manner to convey the configuration that is more consistent with our other technologies. There are interesting discussions on creating the JSON from Powershell script in the Discussions tab. |
Beta Was this translation helpful? Give feedback.
-
To further this discussion and keep everyone's valuable comments - I'm transferring this issue to the Crescendo discussion tab. |
Beta Was this translation helpful? Give feedback.
-
While I applaud the PowerShell team's efforts to make it easier to bring native commands into the object pipeline it seems an odd choice to use JSON instead of the PowerShell-native psd1 format.
An issue I can see right away is that authoring the handlers is a lot less awkward in psd1, because you get syntax highlighting and IntelliSense. And you won't have to fight with quoting.
Beta Was this translation helpful? Give feedback.
All reactions