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

feat(scoop-config): Allow 'hold_update_until' be set manually #5100

Merged
merged 3 commits into from
Aug 16, 2022

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented Aug 11, 2022

Description

Rename update_until to hold_update_until and allow it be set manually in the format such as YYYY/MM/DD, YYYY-MM-DD or any other forms that accepted by [System.DateTime]::Parse()

Motivation and Context

How Has This Been Tested?

image
image

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@niheaven niheaven changed the title feat(scoop-config): Allow 'hold_update_until' be manually set feat(scoop-config): Allow 'hold_update_until' be set manually Aug 11, 2022
@niheaven
Copy link
Member Author

@r15ch13 This should be what you need, right? 😄

@r15ch13
Copy link
Member

r15ch13 commented Aug 11, 2022

Yes 😄

But there is no need for exception handling if TryParse() is used.

[datetime]$hold_update_until = New-Object DateTime
$a = [System.DateTime]::TryParse($cfg_value, $null, [System.Globalization.DateTimeStyles]::AssumeLocal, 
[ref]$hold_update_until)

It simply returns True/False

@yi-Xu-0100
Copy link
Contributor

yi-Xu-0100 commented Aug 11, 2022

@niheaven @r15ch13 Why not try to parse $hold_update_until when use scoop config hold_update_until <wrong_value>? We can reply to the user with the docs link when parse failed, otherwise the calculated actual time when parse succeeded. 😊

@r15ch13
Copy link
Member

r15ch13 commented Aug 11, 2022

function Test-ScoopUpdateOnHold() {
    $hold_update_until = get_config hold_update_until
    if ($null -eq $hold_update_until) {
        return $false
    }

    [datetime]$parsed_date = New-Object DateTime
    if([System.DateTime]::TryParse($hold_update_until, $null, [System.Globalization.DateTimeStyles]::AssumeLocal, [ref]$parsed_date)) {
        if ((New-TimeSpan $parsed_date).TotalSeconds -lt 0) {
            warn "Skipping self-update until $($parsed_date.ToLocalTime())..."
            warn "If you want to update Scoop itself immediately, use 'scoop unhold scoop; scoop update'."
            return $true
        } else {
            warn "Self-update is enabled again!"
            set_config hold_update_until $null | Out-Null
        }
    } else {
        error "'hold_update_until' has been set in the wrong format and was removed."
        error "If you want to disable Scoop self-update for a moment, use 'scoop hold scoop' or 'scoop config hold_update_until <YYYY-MM-DD>/<YYYY/MM/DD>'."
        set_config hold_update_until $null | Out-Null
    }

    return $false
}

And then use Test-ScoopUpdateOnHold inside update_scoop() to return early.

function update_scoop($show_update_log) {
    # snip

    if(Test-ScoopUpdateOnHold) {
        return
    }

    # snip
}

@r15ch13
Copy link
Member

r15ch13 commented Aug 11, 2022

@niheaven @r15ch13 Why not try to parse $hold_update_until when use scoop config hold_update_until <wrong_value>? We can reply to the user with the docs link when parse failed, otherwise the calculated actual time when parse succeeded. 😊

Checking the user input is also a good idea. But that requires a rework of scoop config in general` 😄

@niheaven
Copy link
Member Author

Wow, yes, I was trying to use TryParse but didn't understand what the [ref] is...

I'll fix the code tomorrow using above code and test it again (maybe it is been tested? 🤣 )

Co-authored-by: Richard Kuhnt <r15ch13+git@gmail.com>
@niheaven
Copy link
Member Author

All done @r15ch13

@niheaven niheaven merged commit a9e5a97 into develop Aug 16, 2022
@niheaven niheaven deleted the fix_update_until branch August 16, 2022 02:03
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

3 participants