infinitered / solidarity

Solidarity is an environment checker for project dependencies across multiple machines.
https://infinitered.github.io/solidarity/
MIT License
640 stars 49 forks source link

Option to output warning instead of error and exit process with 0 #250

Closed haakemon closed 1 year ago

haakemon commented 5 years ago

In some cases it would be nice to be able to just ouput that these checks fails as a warning.

F.ex you want to try to upgrade Node to a new version to see if everything behaves as expected. It would be nice to be able to "bypass" the checks with just a warning instead of exiting the process with non-zero exit code and breaking any other steps in the chain.

I can look into adding this feature if it is something you would like to add to the project.

GantMan commented 5 years ago

That sounds like a cool feature! Like --warnOnly or something as a flag?

I'd merge that!

tabrindle commented 5 years ago

If you would like to do this for the entire Solidarity file, you could use a shell || or. This is fairly common practice, and many other libraries have fought against circumventing exit codes as a cli option.

You could also use this clever trick using unterminated escape codes to light up the terminal red, but continue your build. For example, use an npm pre hook.

    "prestart": "solidarity || (echo \"\n\\x1b[41mProject requirements not met: proceed at your own risk.\n\n\" && sleep 5)",

However, I can still see this as a feature where we can control on a per rule basis, using an error vs warning paradigm.

Consider this possible future .solidarity file config.

 "requirements": {
    "npm": [
      {
        "rule": "cli",
        "binary": "npm",
        "semver": "~6.11.3",
        "error": "npm: You have {{installedVersion}}, and need {{wantedVersion}}. Update with `npm install -g npm@{{wantedVersion}}`"
      }
    ],
    "Node": [
      {
        "rule": "cli",
        "binary": "node",
        "warning": true,
        "semver": "~10.17.0",
        "error": "Node: You have {{installedVersion}}, and need {{wantedVersion}}. Update with `nvm install {{wantedVersion}} && nvm alias default {{wantedVersion}}`"
      }
    ]
  }

In this case violating the rule for npm would cause a non-zero exit, however, violating node would output the warning and would allow the process to exit 0.