Giter Club home page Giter Club logo

yeow's Introduction

yeow

yeow is a CLI helper with attitude โ€” part meow, part yargs, and built to spite the both of them.

things yeow does:

  • parse arguments
  • assert types
  • fail if given incorrect arguments

things yeow doesn't do:

  • negate arguments with --no-
  • interpret arguments as an array
  • restrict valid values to a predetermined list

install

$ npm i --save yeow

usage

#!/usr/bin/env node
const args = require("yeow")({
  "exclamation": {
    type: "string",
    required: true
  },
  "int": {
    type: "number",
    aliases: "--integer",
    default: 16
  }
});

console.log(args);
$ ./logger.js "yeow!"
{ exclamation: 'yeow!', int: 16 }

$ ./logger.js "cool!" --integer 100
{ exclamation: 'cool!', int: 100 }

API

yeow(obj)

returns an object of parsed arguments from the passed obj.

obj

type: object

each key is a human-readable argument name. the value is an object with any of:

type

type: string

type of the argument.

possible values:

  • string
  • number
  • file

if this is omitted, the argument will become a simple true/false flag.

required

type: boolean
default: false

whether the argument is required. required arguments ignore aliases and default.

the n-th argument for which required is set to true must be passed as the n-th argument to the program.

missing

type: string

error message to output if the argument is omitted.

if the argument is not required, this will be ignored.

aliases

type: string

valid aliases for the argument, space-slash-space separated.

example values:

  • -a
  • -a / --argument

if the argument is required, this will be ignored.

extensions

type: string

valid file extensions for the argument, space-slash-space separated.

example values:

  • .txt
  • .js / .jsx

if the argument's type is not file, this will be ignored.
if this is omitted, the argument will accept files of any extension.

default

type: string | number

a default value the argument will have if it is omitted. the value's type should match the argument's type.

if the argument is required, this will be ignored.

invalid

type: string

error message to output if the argument is passed with an invalid type.

example

const args = require("yeow")({
  "script": {
    type: "file",
    extensions: ".js",
    required: true,
    missing: "a file must be passed",
    invalid: "not a .js file"
  },
  "delay": {
    type: "number",
    aliases: "-d / --delay",
    default: 1
  },
  "input": {
    type: "string",
    aliases: "--input",
  },
  "verbose": {
    aliases: "-v / --verbose"
  }
});

donate

you can support the development of this project and others via Patreon:

Support me on Patreon

yeow's People

Contributors

sporeball avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cjdenio

yeow's Issues

deobfuscation needed

i have to concede: the current state of the code is pretty terrifying. i do love a good golf (victus is a prime example of that), but doing all that work myself really just created a black box which is nigh impossible to add new features on top of. i now need someone (or myself) to go back and undo that work.

the ideal solution would have to adhere to a few core tenets:

  • doesn't break any existing functionality;
  • makes the code intelligible;
  • allows something else to do size reduction, if any.

the current version does the job in the projects in which it is used, sure - but for further development to ever occur, this needs to be accomplished first.

type checking is overzealous with numbers

because type checking for number arguments uses the unary plus, passing a number or any of the following to an argument of type string will cause yeow to fail:

  • "0012"
  • "0b1100"
  • "0xC"
  • "0o14"
  • '' (converts to 0)

strings should be allowed to be strings (hi!) or numbers in base 10 without leading zeroes (250).
numbers should only be allowed to be in base 10 without leading zeroes (250).

file arguments can only have a single extension

yeow will currently fail if an argument of type string matches /\w+\.\w+/.

this is not ideal, as it means any file passed as an argument must either have a single specific extension, matching /\.\w+/ and given as the argument's type, or absolutely none at all. the ability to use multiple extensions (or any extension!) should be available.

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.