Repository navigation
refactor(simulate): move run state off Flags and exit codes out #519
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
Open
jcogilvie
wants to merge
3
commits into
crossplane:main
Choose a base branch
from
jcogilvie:jco-simulate-runner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−119
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| Copyright 2026 The Crossplane Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // Package exitcode holds the usage exit status and the ExitError the commands | ||
| // share. | ||
| package exitcode | ||
|
|
||
| import "errors" | ||
|
|
||
| // ExitCodeUsage is the status kong exits with on a parse error. Kong does | ||
| // not export it, so it is mirrored here for the flag errors main finds | ||
| // before Parse. | ||
| const ExitCodeUsage = 80 | ||
|
|
||
| // ExitError is an error that sets the command's exit status; it implements | ||
| // kong.ExitCoder. With a nil Err it reports a result that is not an error, | ||
| // such as changes found: main exits with Code without printing anything. | ||
| // Return it by value and unwrapped: main exits silently only when the | ||
| // returned error carries no message besides a silent ExitError, so one | ||
| // wrapped with a message or joined with another error, or a pointer, is | ||
| // printed as an error. | ||
| type ExitError struct { | ||
| // Err is the error to print, or nil to exit silently. | ||
| Err error | ||
|
|
||
| // Code is the status to exit with. | ||
| Code int | ||
| } | ||
|
|
||
| // Error returns Err's message, or an empty string when Err is nil. | ||
| func (e ExitError) Error() string { | ||
| if e.Err == nil { | ||
| return "" | ||
| } | ||
| return e.Err.Error() | ||
| } | ||
|
|
||
| // ExitCode implements kong.ExitCoder. | ||
| func (e ExitError) ExitCode() int { | ||
| return e.Code | ||
| } | ||
|
|
||
| // Unwrap returns Err. | ||
| func (e ExitError) Unwrap() error { | ||
| return e.Err | ||
| } | ||
|
|
||
| // Silent reports whether e exits without printing anything. | ||
| func (e ExitError) Silent() bool { | ||
| return e.Err == nil | ||
| } | ||
|
|
||
| // SilentExit returns the code of a silent ExitError value in err's chain | ||
| // when err has no message of its own, and false otherwise. kong's | ||
| // Context.Run joins the command's error with its AfterRun hooks' errors, so | ||
| // the check can't require err to be the ExitError itself; requiring an empty | ||
| // message still keeps a wrapping or joined error from being swallowed. | ||
| func SilentExit(err error) (int, bool) { | ||
| var e ExitError | ||
| if err == nil || err.Error() != "" || !errors.As(err, &e) || !e.Silent() { | ||
| return 0, false | ||
| } | ||
| return e.Code, true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep the simulate-specific exit codes in the simulate package, just moving the global ones (like
Usage) and the shared machinery.