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(shell): run shell command conditionally #321

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Clumsy-Coder
Copy link

@Clumsy-Coder Clumsy-Coder commented Aug 12, 2022

what

  • Run shell command conditionally (optional)
  • Update README docs

how

  • the shell directive will check if the 'if' property is available.
    • If it is, it will run the command in 'if' property.
    • If the command results in a return 0 code or 'true', then the 'command' property will run.
    • If the condition to run the command is a non 0 code or 'false', the shell command won't run
  • dotbot config example:
- shell:
    - command: echo "this is running on a MacOS"
      if: uname -s | grep -i "Darwin"
  • running shell command regardless
- shell:
    - command: echo "This should run regardless"
  • dotbot config example: skipping command if false
- shell:
    - command: echo "This command should be skipped"
      if: false

why

where

  • file changed in ./dotbot/plugins/shell.py

usage

Create dotbot config

- shell:
    - command: echo "this is running on a MacOS"
      if: uname -s | grep -i "Darwin"
- shell:
    - command: echo "This command should be skipped"
      if: false
- shell:
    - command: apt update && apt upgrade -y
      if: lsb_release -i | grep -io 'debian'
      description: Update APT package repository

    - command: dnf update -y
      if: lsb_release -i | grep -io 'fedora'
      description: Update DNF package repository

NOTE

  ## what
  - add feature to run shell command (optionally)

  ## how
  - the shell directive will check if the 'if' property is available.
    If it is, it will run the command in 'if' property.
    If the command results in a return 0 code or 'true', then the
    'command' property will run.
    If the condition to run the command is a non 0 code or 'false',
      the shell command won't run
  - dotbot config example:
    ```yaml
    - shell:
        - command: echo "this is running on a MacOS"
          if: uname -s | grep -i "Darwin"
    ```
  - dotbot config example: skipping command if false
    ```yaml
    - shell:
        - command: echo "This command should be skipped"
          if: false
    ```

  ## why
  - can run the shell command conditionally
  - can use multiple dotbot configs to run different OS
    - Ex: incorporating it in https://github.com/ecarlson94/dotbot-template

  ## where
  - file changed in `./dotbot/plugins/shell.py`

  ## usage
  Create dotbot config
    ```yaml
    - shell:
        - command: echo "this is running on a MacOS"
          if: uname -s | grep -i "Darwin"
    ```

    ```yaml
    - shell:
        - command: echo "This command should be skipped"
          if: false
    ```
  ## what
  - add documentation on using shell command conditionally

  ## how

  ## why

  ## where

  ## usage
@Clumsy-Coder
Copy link
Author

Pull Request connected to issue #312

@Clumsy-Coder Clumsy-Coder marked this pull request as ready for review August 12, 2022 03:17
@Clumsy-Coder
Copy link
Author

I tested it as much as I can.

This is first time working in Python code.

So, if issue surfaces, let me know

@wonderbeyond
Copy link

Hi, I just made the dotbot-if plugin, and found it's sharing the similar idea with this PR.

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.

2 participants