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) easyConfig [a.k.a. shorthand config] #5

Closed
justsml opened this issue May 14, 2022 · 0 comments · Fixed by #8
Closed

(feat) easyConfig [a.k.a. shorthand config] #5

justsml opened this issue May 14, 2022 · 0 comments · Fixed by #8
Assignees
Labels
enhancement New feature or request

Comments

@justsml
Copy link
Contributor

justsml commented May 14, 2022

Add support for simplified configuration:

export const config = easyConfig({
  "url": ['--url', '-u', 'APP_URL'],
  "port": ['--port', '-p', 'PORT'],
  "debug": ['--debug', '-D'],
});

Type coercions can be provided by a convert function in the args array.

import { easyConfig } from '@elite-libs/auto-config';

// Example Validators
const parsePort = port => (port = parseInt(port ?? 1234, 10), port > 1000 && port < 60000 ? port : null);
const parseAcctId = input => zod.any(input).refine(Number).safeParse(input)?.data;

export const config = easyConfig({
  "siteUrl": ['--site-url', 'SITE_URL'],
  "port": ['--port', 'PORT', parsePort],
  "accountId": ['--accountId', '-a', parseAcctId],
});

Post-MVP Stretch / Future Goal

Options

  • Support type annotations and constraint tokens (starting with !, @, or #)
    • ['!required', '!string', '--url', 'URL']
    • { "string": ["URL", "--url"] }
export const config = denseConfig({
  "url": ['!required', '!string', '--url', '-u', 'APP_URL'],
  "port": ['--port', '-p', 'PORT'],
  "debug": ['--debug', '-D'],
});
@justsml justsml changed the title Easy Config - Shorthand mode (feat) easyConfig, a.k.a. Shorthand config May 15, 2022
@justsml justsml changed the title (feat) easyConfig, a.k.a. Shorthand config (feat) easyConfig [a.k.a. shorthand config] May 15, 2022
@justsml justsml added the enhancement New feature or request label May 15, 2022
@justsml justsml self-assigned this May 15, 2022
@justsml justsml linked a pull request May 15, 2022 that will close this issue
justsml added a commit that referenced this issue May 15, 2022
* Fixing minor Enum type issues

* Add easyConfig MVP, w/ minor typing fixes. Completes #5

* Update & clean deps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant