Skip to content

commands: add new generic --skip-if command line options #120

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

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

phlogistonjohn
Copy link
Collaborator

Depends on: #119

Previously, sambacc had the --skip-if-file= command line option that
would skip running a command if a named file exists. I have a need for
doing something similar for environment variable contents. In order to
avoid needing to add a plethora of new --skip-if-x type options over
time, add a more generic --skip-if= option and have the value contain
an initial prefix like file: or env: that determines how the rest of
the value will be parsed and how the skip will be determined (or not).
Deprecate --skip-if-file.

Maybe it's a case of over engineering, but at least it's easy to unit
test.

Examples:

  • --skip-if=env:CHAT==yes, if the environment variable CHAT contains
    a value equal to "yes" the command will be skipped
  • --skip-if=file:/foo/bar if the file /foo/bar exists the command
    will be skipped
  • --skip-if=file:!/foo/bar if the file /foo/bar does not exist the command
    will be skipped
  • --skip-if=env:MODE!=777, if the environment variable MODE contains
    a value not equal to "777" the command will be skipped
  • --skip-if=always:, always skip this command (mainly to be used for
    testing/hacking on things)

@phlogistonjohn
Copy link
Collaborator Author

cc: @avanthakkar - for an additional review & peek into this code base

Copy link

dpulls bot commented Jun 19, 2024

🎉 All dependencies have been resolved !

@phlogistonjohn phlogistonjohn marked this pull request as ready for review June 19, 2024 13:33
synarete
synarete previously approved these changes Jun 19, 2024
Copy link
Collaborator

@synarete synarete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but see minor comments

@mergify mergify bot dismissed synarete’s stale review June 19, 2024 14:59

Pull request has been modified.

@phlogistonjohn
Copy link
Collaborator Author

I noticed a stray debugging print statement was still in the unit test file. It's now removed.

@phlogistonjohn phlogistonjohn requested a review from synarete June 19, 2024 15:01
synarete
synarete previously approved these changes Jun 19, 2024
Add a generic lib for skipping the execution of a sambacc command
based on file presence or environment variable contents. There's
also an 'always:' rule for completeness & testing purposes.

Signed-off-by: John Mulligan <[email protected]>
Previously, sambacc had the `--skip-if-file=` command line option that
would skip running a command if a named file exists. I have a need for
doing something similar for environment variable contents. In order to
avoid needing to add a plethora of new --skip-if-x type options over
time, add a more generic `--skip-if=` option and have the value contain
an initial prefix like `file:` or `env:` that determines how the rest of
the value will be parsed and how the skip will be determined (or not).
Deprecate `--skip-if-file`.

Maybe it's a case of over engineering, but at least it's easy to unit
test.

Examples:
* `--skip-if=env:CHAT==yes`, if the environment variable `CHAT` contains
  a value equal to "yes" the command will be skipped
* `--skip-if=file:/foo/bar` if the file `/foo/bar` exists the command
  will be skipped
* `--skip-if=file:!/foo/bar` if the file `/foo/bar` does not exist the command
  will be skipped
* `--skip-if=env:MODE!=777`, if the environment variable `MODE` contains
  a value not equal to "777" the command will be skipped
* `--skip-if=always:`, always skip this command (mainly to be used for
  testing/hacking on things)

Signed-off-by: John Mulligan <[email protected]>
@mergify mergify bot dismissed synarete’s stale review June 19, 2024 16:37

Pull request has been modified.

Copy link
Collaborator

@avanthakkar avanthakkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@synarete synarete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@phlogistonjohn phlogistonjohn requested a review from anoopcs9 June 20, 2024 11:57
@mergify mergify bot merged commit 3a49ce2 into samba-in-kubernetes:master Jun 20, 2024
9 checks passed
@phlogistonjohn phlogistonjohn deleted the jjm-skips branch June 20, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants