Giter Club home page Giter Club logo

Comments (4)

sveeke avatar sveeke commented on May 24, 2024

4dab63d

Added case *) for non-defined entries as a start.

from linux-serverbot.

sveeke avatar sveeke commented on May 24, 2024

This is added in nozel-org/serverbot@581f717. At first I was planning to add some rather advanced/extensive argument validation, where all exact combinations of possible commands are checked. But in the end I found this a little bit too much, so I will do it with two simple checks:

function requirement_argument_validity {

    # amount of arguments less than one or more than two result in error
    if [ "${#}" -eq '0' ] || [ "${#}" -gt '2' ]; then
        error_invalid_option
    fi
}
        # other
        *)
            ARGUMENT_NONE='1'
            shift
            ;;
    elif [ "${ARGUMENT_NONE}" == '1' ]; then
        error_invalid_option
    fi

This will allow users to still use a combination of one valid single argument (i.e. --version) and one invalid argument, but the script should still work fine in this scenario. Maybe there are better ways of doing this though.

from linux-serverbot.

sveeke avatar sveeke commented on May 24, 2024

Despite the last comment I wanted to improve it still, so I added:

function requirement_argument_validity {

    # amount of arguments less than one or more than two result in error
    if [ "${ARGUMENTS}" -eq '0' ] || [ "${ARGUMENTS}" -gt '2' ]; then
        error_invalid_option
    fi

    # options are incompatible with features
    if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_FEATURE}" == '1' ]; then
        error_invalid_option
    fi

    # options are incompatible with methods
    if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_METHOD}" == '1' ]; then
        error_invalid_option
    fi
}

And in the case loop all features, methods and options will populate the variables with 1.

from linux-serverbot.

sveeke avatar sveeke commented on May 24, 2024

Extended it further:

function requirement_argument_validity {
    # amount of arguments less than one or more than two result in error
    if [ "${ARGUMENTS}" -eq '0' ] || [ "${ARGUMENTS}" -gt '2' ]; then
        error_wrong_number_of_arguments
    fi

    # options are incompatible with features
    if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_FEATURE}" == '1' ]; then
        error_options_cannot_be_combined
    fi

    # options are incompatible with methods
    if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_METHOD}" == '1' ]; then
        error_options_cannot_be_combined
    fi

    # if there are two arguments, only a combination of feature and method is possible
    if [ "${ARGUMENTS}" -eq '2' ]; then
        # features require methods and vice versa, so they should add to two.
        ARGUMENT_FEATURE_AND_METHOD="$((${ARGUMENT_FEATURE}+${ARGUMENT_METHOD}))"
        # and otherwise result in an error
        if [ "${ARGUMENT_FEATURE_AND_METHOD}" -ne '2' ]; then
            error_no_feature_and_method
        fi
    fi
}

from linux-serverbot.

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.