Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readability #16

Merged
merged 7 commits into from
Aug 14, 2021
Merged

Readability #16

merged 7 commits into from
Aug 14, 2021

Conversation

Trenly
Copy link
Owner

@Trenly Trenly commented Aug 13, 2021

@OfficialEsco I haven't fully tested this yet, but I'm 90% sure it will work.

I added a function just to make things more readable.

String.IsValid {String} [-MinLength] [-MaxLength] [-MatchPattern]
  Returns True if and only if
    - String.Length >= MinLength  AND
    - String.Length <= MaxLength AND
    - String -match MatchPattern

I also did abstract everything to a hashtable just to keep things readable and for making future updates easier

@OfficialEsco
Copy link
Collaborator

OfficialEsco commented Aug 13, 2021

Hahaha you just do the things don't you, glad you find inspiration in my ideas 😁
Sure it does kinda look better 🙄

From looking at the code you might have broken the $Max variable on line 591, 596, 601 and 606.

FileExtensions also have a Pattern, but i don't think we can implement it as its multi string?

Edit: Yupp

[Optional] Enter any File Extensions the application could support. For example: html, htm, url (Max )
FileExtensions:

[Optional] Enter any Protocols the application provides a handler for. For example: http, https (Max )
Protocols:

[Optional] Enter any Commands or aliases to run the application. For example: msedge (Max )
Commands:

[Optional] List of additional non-zero installer success exit codes other than known default values by winget (Max )
InstallerSuccessCodes:

@Trenly
Copy link
Owner Author

Trenly commented Aug 13, 2021

Hahaha you just do the things don't you, glad you find inspiration in my ideas 😁
Sure it does kinda look better 🙄

From looking at the code you might have broken the $Max variable on line 591, 596, 601 and 606.

FileExtensions also have a Pattern, but i don't think we can implement it as its multi string?

Edit: Yupp

[Optional] Enter any File Extensions the application could support. For example: html, htm, url (Max )
FileExtensions:

[Optional] Enter any Protocols the application provides a handler for. For example: http, https (Max )
Protocols:

[Optional] Enter any Commands or aliases to run the application. For example: msedge (Max )
Commands:

[Optional] List of additional non-zero installer success exit codes other than known default values by winget (Max )
InstallerSuccessCodes:

Oop; Should be an easy fix. I’ll do it when I get home.

We could probably do file extensions enum, I think we already do something similar for Architecture

Edit: Misread what you meant by multistring; Might still be possible though

@OfficialEsco
Copy link
Collaborator

OfficialEsco commented Aug 13, 2021

We could probably do file extensions enum, I think we already do something similar for Architecture

There is no enum for FileExtensions, however we should probably start looking at error messages so it shows why it failed..

"FileExtensions": {
      "type": [ "array", "null" ],
      "items": {
        "type": "string",
        "pattern": "^[^\\\\/:\\*\\?\"<>\\|\\x01-\\x1f]+$",
        "maxLength": 64
      },
      "maxItems": 256,
      "uniqueItems": true,
      "description": "List of file extensions the package could support"
    }
},
        "Architecture": {
          "type": "string",
          "enum": [
            "x86",
            "x64",
            "arm",
            "arm64",
            "neutral"
          ],
          "description": "The installer target architecture"
        }

Edit:
We can probably look into enum for InstallModes first, might be a easier path to finding out how to do pattern for FileExtensions

"InstallModes": {
      "type": [ "array", "null" ],
      "items": {
        "title": "InstallModes",
        "type": "string",
        "enum": [
          "interactive",
          "silent",
          "silentWithProgress"
        ]
      },

Edit2: AHHH yeah you need to look into the MaxItems issue because last time i tried it your PromptInstallerManifestValue function restricted me

@Trenly
Copy link
Owner Author

Trenly commented Aug 13, 2021

Edit2: AHHH yeah you need to look into the MaxItems issue because last time i tried it your PromptInstallerManifestValue function restricted me

What do you mean?

@OfficialEsco
Copy link
Collaborator

Edit2: AHHH yeah you need to look into the MaxItems issue because last time i tried it your PromptInstallerManifestValue function restricted me

What do you mean?

The current issue is that you can't do Write-Host "Text here $Variable.MaxItems" you have to do Write-Host "Text here", $Variable.MaxItems but it got errors when i did that

@Trenly
Copy link
Owner Author

Trenly commented Aug 13, 2021

Edit2: AHHH yeah you need to look into the MaxItems issue because last time i tried it your PromptInstallerManifestValue function restricted me

What do you mean?

The current issue is that you can't do Write-Host "Text here $Variable.MaxItems" you have to do Write-Host "Text here", $Variable.MaxItems but it got errors when i did that

The $( ) operator is really helpful

@OfficialEsco
Copy link
Collaborator

Interesting.. learned something new, now i know the proper use for @( ) and $( ) 👀

Tools/YamlCreate.ps1 Outdated Show resolved Hide resolved
@Trenly
Copy link
Owner Author

Trenly commented Aug 14, 2021

We could probably do file extensions enum, I think we already do something similar for Architecture

There is no enum for FileExtensions, however we should probably start looking at error messages so it shows why it failed..

"FileExtensions": {
      "type": [ "array", "null" ],
      "items": {
        "type": "string",
        "pattern": "^[^\\\\/:\\*\\?\"<>\\|\\x01-\\x1f]+$",
        "maxLength": 64
      },
      "maxItems": 256,
      "uniqueItems": true,
      "description": "List of file extensions the package could support"
    }

Edit:
We can probably look into enum for InstallModes first, might be a easier path to finding out how to do pattern for FileExtensions

"InstallModes": {
      "type": [ "array", "null" ],
      "items": {
        "title": "InstallModes",
        "type": "string",
        "enum": [
          "interactive",
          "silent",
          "silentWithProgress"
        ]
      },

I think I took care of this validation. I don't have it removing duplicate extensions though. Maybe that's something to look at later. I agree that error messages should be next

@OfficialEsco
Copy link
Collaborator

Was going to report a issue with the InstallModes but then i realized it was a typo, so it clearly works 😁
Probably not getting to stresstest before next week as there are way too few packages on the weekend

@OfficialEsco
Copy link
Collaborator

@quhxl since you go trough more packages than only GitHub releases and add Metadata would you mind testing this?
Not sure if you've updated/tested the YamlCreate since you've been gone for a few days, we appreciate any feedback :)

@OfficialEsco OfficialEsco merged commit 98510f6 into YamlParsing Aug 14, 2021
@Trenly Trenly deleted the readability branch August 20, 2021 18:15
Trenly added a commit that referenced this pull request Aug 20, 2021
* Add Comparison Functions for Readability

* Simplify Validation Function

* Fix: Missing text

* Remove spaces from split function

* Fix: Resolve renamed variable

* Validate Installer Modes

* Validate File Extensions with Pattern and Length
Trenly added a commit that referenced this pull request Sep 14, 2021
* Add Comparison Functions for Readability

* Simplify Validation Function

* Fix: Missing text

* Remove spaces from split function

* Fix: Resolve renamed variable

* Validate Installer Modes

* Validate File Extensions with Pattern and Length
Trenly added a commit that referenced this pull request Sep 27, 2021
* Add Comparison Functions for Readability

* Simplify Validation Function

* Fix: Missing text

* Remove spaces from split function

* Fix: Resolve renamed variable

* Validate Installer Modes

* Validate File Extensions with Pattern and Length
Trenly added a commit that referenced this pull request Oct 13, 2021
* Add Comparison Functions for Readability

* Simplify Validation Function

* Fix: Missing text

* Remove spaces from split function

* Fix: Resolve renamed variable

* Validate Installer Modes

* Validate File Extensions with Pattern and Length
Trenly added a commit that referenced this pull request Nov 3, 2021
* Install powershell-yaml

* Enforce ordering of keys

* Create function for adding list parameters

* Write Version Manifest using Yaml Parser

* Add To-Do Section

* Rebase on master and cleanup commit history

* Revert inadvertent changes from testing

* Implement logic for installers using YAML parser

* Fix statement in incorrect position

* Remove RAW writing

* Begin reading MultiManifests using Yaml parser

* Cleanup unneeded variables

* Bump Version

* Read parameters from singletons

* Add Product Code

* Abstract ReadInstallerManifest to sub-function

* Fix: Handle uninitialized variables

* Merge New/Update, add EditMetadata

* Fix: Change EditMetadata to work on singleton manifests

* Fix: Update Git commit messages for accuracy

* Remove Empty Manifest Folders

* Fix: Correct text

* Fix: Remove code for testing

* Feature: If old manifests exist, update in place to preserve extra keys

* Fix: Null Error when creating new

* Fix: Cast only when installer code

* Fix: Respect installer locale

* Fix: Use UTF8 Encoding

* Sort Yaml Keys

* Git error handling

* Fixed Moniker prompt for NewLocale

* minItems, maxItems, pattern, variable fix

* Implemented minItems from Schema
* Implemented maxItems from Schema
* Implemented pattern from Schema
* Implemented available Architecture's from Schema
* Implemented available InstallerType's from Schema
* Added $script: to some variables which needs to stay throughout the script

Only tested with one manifest as of now

Cleanup If/Else logic & Rebase on master

* Update method of getting Product Code from installer

* SignatureSha256 and PackageFamilyName (#5)

* More CommitTypes

* Fill in PR Parameters microsoft#21940 (#4)

* Detect PackageFamilyName for MSIX/APPX (#8)

* Update YamlCreate.ps1

* Update YamlCreate.ps1

* Exclude .validation (#9)

* Exclude .validation

* Added exclude to ExistingVersions

Co-authored-by: Levvie - she/her <11600822+ItzLevvie@users.noreply.github.com>

* Add new line for PackageFamilyName (#10)

* Standardize Keypress Menus (#11)

* Standardize Keypress Menus

* Fix: Use variable instead of pipeline

* Fix Help Texts & Spacing

* Cleanup Git Messages

* Filter by Yaml

* Remove debugging line

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

Co-authored-by: Kaleb Luedtke <kaleb.carver.luedtke@jci.com>
Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* Replaced PrBodyContentReply `n with array (#12)

* Menu reduction (#13)

* Simplify Code + Make Issues Entry Safer

* Check issue validity

* Fix unintended Revert

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* Fix unintended Revert

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* Fix unintended Revert

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* More patterns (#15)

Added pattern for

* PackageIdentifier
* PackageVersion
* PackageFamilyName
* PackageLocale

* Readability (#16)

* Add Comparison Functions for Readability

* Simplify Validation Function

* Fix: Missing text

* Remove spaces from split function

* Fix: Resolve renamed variable

* Validate Installer Modes

* Validate File Extensions with Pattern and Length

* Add Custom Error Class (#18)

* Create function for adding list parameters

* Remove RAW writing

* Remove Empty Manifest Folders

* minItems, maxItems, pattern, variable fix

* Implemented minItems from Schema
* Implemented maxItems from Schema
* Implemented pattern from Schema
* Implemented available Architecture's from Schema
* Implemented available InstallerType's from Schema
* Added $script: to some variables which needs to stay throughout the script

* Add Custom Error Class

* Cleanup Class Constructor

* Additional error messages + cleanup

* Continue adding error messages

* Switched Local formatter to OTBS + Static Strings (Where applicable)

* Fix Spacing

* Remove unused variables from rebase

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* Fix: Check for package before do-until

* Finish Locale Errors

* Fix Spacing Issues

* Make Enums Case Sensitive

* Fix Unique Items + Incorrect Variables

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>

* Subfolder fix (#21)

* Fix: Subfolder Exists Erroring

* Return

* Write Unused Keys as Comments (#22)

* Write Unused Keys as Comments

* Exclude certain keys from appearing as comments

* Comment only Locale + Version

* Quick Update, Function Reduction, Detect Installer Types, Detect Installer Architectures, and Comments (#27)

* Update YamlCreate.ps1

* auto-detect installer architecture

* Fix #27 (comment)

* Fix auto-detection

* Apply suggestions from code review

Co-authored-by: Kaleb Luedtke <trenlymc@gmail.com>

* Move Test + Submit to main

* Update Tools/YamlCreate.ps1

* fix quick-update check

* Reduce input required for quick version update (#4)

* Reduce input required for quick version update

* Fix Product Code

* Don't add null product code if no product code key exists

* improve quick update

* Move prompt outside of Read-Info for clarity

* Move Update Prompt outside of Read-Info for clarity

* Update Messages

* if there are any errors due to this commit, i will revert changes

* Add Comments for code clarity

Co-authored-by: Kaleb Luedtke <trenlymc@gmail.com>

* Fix error from when functions were moved

* Handle Manifest Level Parameters (#34)

* Begin Handling Manifest Level Parameters

* Fix InstallModes

* Add delete manifest functionality (#39)

* Add functionality to manually delete manifests

* Add settings file and script documentation (#38)

* Do not default installer locale

* Add a script settings file with documentation

* Add setting to suppress quick update warning

* Remove accidental file inclusion

* Fix: Update SignatureSha256 in quick update mode (#41)

* Change Settings to allow for negative suppression (#46)

* Change Settings to allow for negative suppression

* Fix sample settings file

* Invalid SandboxTest variable

Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

Co-authored-by: Kaleb Luedtke <kaleb.carver.luedtke@jci.com>
Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>
Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

* Cleaner references to linked issues (#49)

* Command Line Arguments (#50)

* Add switch for settings

* Allow PackageIdentifier and PackageVersion to be passed as optional parameters

* Add -help switch and documentation

* Settings File Location

* Fix spacing issue [#49] #51

Co-authored-by: Kaleb Luedtke <kaleb.carver.luedtke@jci.com>
Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

* Fix Parameter Reading and Condensing(#54)

* Fix: Allow InstallerSwitch keys to be split between installer level and manifest level on a per-key basis

* Fix: Save parameters to variables before removing them from manifest level

* Fix: Sandboxtest not working

* Fix: Prompt for PFN if file does not exist (#55)

* Auto Mode (#58)

* Auto Mode

* Fix for same version

* Keep ProductCodes for .exe files

* Keep ProductCodes for .exe files in Option-2

* Simplify function names, add debug info (#62)

* Fix: Allow autoupdate to update old package versions (#66)

* Make Simple Update automatically detect Sha256, SignatureSha256, and ProductCode without prompts (#61)

* Make Simple Update automatically detect Sha256, SignatureSha256, and ProductCode without prompts

* Add Parameter Mode (#64)

* Add Parameter Mode

* Update YamlCreate.ps1

* Update YamlCreate.md

Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

* Use Unique Branch Names (#67)

* Use Unique Branch Names

* Process Branch Names Safely

* Fix: Allow values other than en-US for default locale (#70)

* Made it so git config was only modified for the local repo. (#72)

* Only modify git config for local repo.

* Fixed 2214.

* Support for settings on Linux and macOS (#73)

* Support for settings on Linux and macOS

* Easton's suggestion

* Update YamlCreate.md

* Update Tools/YamlCreate.ps1

Co-authored-by: Kaleb Luedtke <trenlymc@gmail.com>

* Update YamlCreate.ps1

Co-authored-by: Kaleb Luedtke <trenlymc@gmail.com>

* Check for open PR's before submitting (#69)

* Check for open PR's before submitting

* Rebase on c82b39f

* Use API instead of CLI

* Exit when user-choice to terminate

Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>

* Throw when script error (#74)

* Fix: Add locale when converting from singleton (#75)

* Fix: Branch names when deleting (#79)

* Fix: Don't check for PRs on deletion (#80)

* Update PR Content when removing a manifest (#82)

* Update PR Content when removing a manifest

* More realistic character count limits

* Add is:pr to exclude issues from results (#88)

* Ensure file names are valid before saving (#85)

* Ensure file names are valid before saving

* Fix: Catch when content disposition doesn't exist

* Fix UserAgent not following redirects

* Additional Web Request Parameters

* Fix: Min descriptor length + Agent

* Fix: Escape Regex in variables (#91)

* Fix: Only add moniker to defaultLocale (#92)

* Chore: Add references to YamlCreate documentation (#93)

* Typo (#94)

* Chore: Add note to enable settings

Co-authored-by: denelon <denelon@microsoft.com>

* Chore: Remove To-do message

* Update YamlCreate.ps1

* Move integer validation (#99)

* Rename String.Validate -> Test-String (#101)

* Suppress Write-Host warnings from ScriptAnalyzer

* Fix missing constructor parameter

* Rename Write-Locale-Manifests -> Write-LocaleManifest

* Rename Write-Version-Manifest -> Write-VersionManifest

* Rename Write-Installer-Manifest -> Write-InstallerManifest

* Rename Read-WinGet-LocaleManifest -> Read-LocaleMetadata

* Rename Read-WinGet-InstallerManifest -> Read-InstallerMetadata

* Rename Read-Installer-Values-Minimal -> Read-QuickInstallerEntry

* Rename Read-Installer-Values -> Read-InstallerEntry

* Rename Enter-PR-Parameters -> Read-PRBody

* Rename Write-Colors -> Write-MulticolorLine

* Use Named Parameters for AddYamlParameter

* Use Named Parameters for AddYamlListParameter

* Use Named Parameters for PromptInstallerManifestValue

* Support ShouldProcess for removing manifests

* Move Downloading of installer to a separate function

* More function name updates

* Fix: Download Method (#107)

* Check for version when setting proxy (#109)

* Use defaultLocale due to microsoft/winget-cli#1646 resolving microsoft/winget-cli#1595

Co-authored-by: Esco <OfficialEsco@users.noreply.github.com>
Co-authored-by: Vedant Mohan Goyal <83997633+vedantmgoyal2009@users.noreply.github.com>
Co-authored-by: Levvie - she/her <11600822+ItzLevvie@users.noreply.github.com>
Co-authored-by: Kaleb Luedtke <kaleb.carver.luedtke@jci.com>
Co-authored-by: Easton Pillay <easton@planeteaston.com>
Co-authored-by: denelon <denelon@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants