Coder Social home page Coder Social logo

Comments (6)

DannyBen avatar DannyBen commented on June 16, 2024 1

Nevermind - I see the problem.

# bashly.yml
name: cli
help: Sample application
version: 0.1.0

args:
- name: file
  default: README.md
  validate: file_exists

with bashly add validations.

I will need to refactor the validations to run after the conversion of the command input to the args array.

from bashly.

DannyBen avatar DannyBen commented on June 16, 2024 1

See #493, which should fix the problem.
Can you test with the edge version?

from bashly.

DannyBen avatar DannyBen commented on June 16, 2024 1

Alright. I will release in a few days (allowing more time for more commits). Thanks for the report.

from bashly.

DannyBen avatar DannyBen commented on June 16, 2024

A default value is by definition, allowed.
I need an example (minimal bashly.yml and other reproduction steps, if any).

from bashly.

keilmillerjr avatar keilmillerjr commented on June 16, 2024

Thank you for the swift response. Here's what I am working on. go-yq arch package is a dependency.

# bashly.yml
name: hyprmenu-power
help: Power Menu
version: 0.1.0

commands:
- name: show
  alias: d
  help: Show power menu
  default: force

  args:
  - name: config
    required: false
    help: Path to config file
    default: /usr/local/etc/hyprmenu/power.yaml
    validate: file_exists
    validate: config_format

  examples:
  - hyprmenu-power show
  - hyprmenu-power show /usr/local/etc/hyprmenu/power.yaml

# src/lib/validations/validate_config_format.yaml
validate_config_format() {
  [[ $(yq eval ".confirmation_menu.labels | length" $1) -eq 2 ]] || echo "incorrect length of confirmation menu labels in $1"

  [[ $(yq eval ".main_menu.labels | length" $1) -eq $(yq eval ".main_menu.confirmations | length" $1) \
    && $(yq eval ".main_menu.labels | length" $1) -eq $(yq eval ".main_menu.commands | length" $1) ]] \
    || echo "Unmatching length of main menu labels, confirmation and commands in $1"
}

# /usr/local/etc/hyprmenu/power.yaml
confirmation_menu:
  labels:
    -   Yes
    -   No
    - test
main_menu:
  labels:
    - ⭘  Power Off
    - ⏼  Reboot
    - ⏾  Suspend
    -   Hibernate
    -   End Session
    -   Lock Screen
  confirmations:
    - true
    - true
    - false
    - false
    - true
    - false
  commands:
    - systemctl poweroff
    - systemctl reboot
    - systemctl suspend
    - systemctl hibernate
    - hyprctl dispatch exit
    - swaylock

The custom validation should check and fail if the confirmation_menu labels array does not have two items. Inserted - test to force a failure. Both tests should fail, in my opinion. However, with a default value being applied, the validation is skipped.

./hyprmenu-power show
args:
- ${args[config]} = /usr/local/etc/hyprmenu/power.yaml
./hyprmenu-power show /usr/local/etc/hyprmenu/power.yaml
validation error in CONFIG:
incorrect length of confirmation menu labels in /usr/local/etc/hyprmenu/power.yaml

from bashly.

keilmillerjr avatar keilmillerjr commented on June 16, 2024

See #493, which should fix the problem. Can you test with the edge version?

Fully tested and working. Thank you so much.

Important to note, there is an error in my shared bashly.yml from prior comment. References to multiple validations does not work. That was an error in my part, misunderstanding of usage. I combined the validations into one single validation file and all works well.

from bashly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.