Skip to content

Un CLI para hacer peticiones a una API que devuelve datos sobre Articulos, Slides, e Imagenes de galeria

Notifications You must be signed in to change notification settings

00frank/apiRequester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apiRequester



Un CLI capaz de hacer peticiones a una API que devuelve datos sobre Articulos, Slides, e Imagenes de galeria
>_ En inglés, command-line interface, CLI, es un método que permite a los usuarios dar instrucciones a un programa por medio de comandos simples▌


Podes ver un video en funcionamiento del cli en el siguiente video de YouTube (Ejemplo de peticiones al modelo Slider)



Creado por 00frank, Enquirer is fast, easy to use, and lightweight enough for small projects, while also being powerful and customizable enough for the most advanced use cases.

  • Fast - Loads in ~4ms (that's about 3-4 times faster than a single frame of a HD movie at 60fps)
  • Lightweight - Only one dependency, the excellent ansi-colors by Brian Woodward.
  • Well tested - All prompts are well-tested, and tests are easy to create without having to use brittle, hacky solutions to spy on prompts or "inject" values.
  • Examples - There are numerous examples available to help you get started.

❯ Getting started

Get started with Enquirer, the most powerful and easy-to-use Node.js library for creating interactive CLI prompts.


❯ Install

Install with npm:

$ npm install enquirer --save

Install with yarn:

$ yarn add enquirer

Install Enquirer with NPM

(Requires Node.js 8.6 or higher. Please let us know if you need support for an earlier version by creating an issue.)


❯ Usage

Single prompt

The easiest way to get started with enquirer is to pass a question object to the prompt method.

const { prompt } = require('enquirer');

const response = await prompt({
  type: 'input',
  name: 'username',
  message: 'What is your username?'
});

console.log(response); // { username: 'jonschlinkert' }

(Examples with await need to be run inside an async function)

Multiple prompts

Pass an array of "question" objects to run a series of prompts.

const response = await prompt([
  {
    type: 'input',
    name: 'name',
    message: 'What is your name?'
  },
  {
    type: 'input',
    name: 'username',
    message: 'What is your username?'
  }
]);

console.log(response); // { name: 'Edward Chan', username: 'edwardmchan' }

List Prompt

Prompt that returns a list of values, created by splitting the user input. The default split character is , with optional trailing whitespace.

Enquirer List Prompt

Example Usage

const { List } = require('enquirer');
const prompt = new List({
  name: 'keywords',
  message: 'Type comma-separated keywords'
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);

MultiSelect Prompt

Prompt that allows the user to select multiple items from a list of options.

Enquirer MultiSelect Prompt

Example Usage

const { MultiSelect } = require('enquirer');

const prompt = new MultiSelect({
  name: 'value',
  message: 'Pick your favorite colors',
  limit: 7,
  choices: [
    { name: 'aqua', value: '#00ffff' },
    { name: 'black', value: '#000000' },
    { name: 'blue', value: '#0000ff' },
    { name: 'fuchsia', value: '#ff00ff' },
    { name: 'gray', value: '#808080' },
    { name: 'green', value: '#008000' },
    { name: 'lime', value: '#00ff00' },
    { name: 'maroon', value: '#800000' },
    { name: 'navy', value: '#000080' },
    { name: 'olive', value: '#808000' },
    { name: 'purple', value: '#800080' },
    { name: 'red', value: '#ff0000' },
    { name: 'silver', value: '#c0c0c0' },
    { name: 'teal', value: '#008080' },
    { name: 'white', value: '#ffffff' },
    { name: 'yellow', value: '#ffff00' }
  ]
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);

// Answer: ['aqua', 'blue', 'fuchsia']

Numeral Prompt

Prompt that takes a number as input.

Enquirer Numeral Prompt

Example Usage

const { NumberPrompt } = require('enquirer');

const prompt = new NumberPrompt({
  name: 'number',
  message: 'Please enter a number'
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);

Password Prompt

Prompt that takes user input and masks it in the terminal. Also see the invisible prompt

Enquirer Password Prompt

Example Usage

const { Password } = require('enquirer');

const prompt = new Password({
  name: 'password',
  message: 'What is your password?'
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);

Quiz Prompt

Prompt that allows the user to play multiple-choice quiz questions.

Enquirer Quiz Prompt

Example Usage

const { Quiz } = require('enquirer');

 const prompt = new Quiz({
  name: 'countries',
  message: 'How many countries are there in the world?',
  choices: ['165', '175', '185', '195', '205'],
  correctChoice: 3
});

 prompt
  .run()
  .then(answer => {
    if (answer.correct) {
      console.log('Correct!');
    } else {
      console.log(`Wrong! Correct answer is ${answer.correctAnswer}`);
    }
  })
  .catch(console.error);

Quiz Options

Option Type Required Description
choices array Yes The list of possible answers to the quiz question.
correctChoice number Yes Index of the correct choice from the choices array.

↑ back to: Getting Started · Prompts


Choice properties

The following properties are supported on choice objects.

Option Type Description
name string The unique key to identify a choice
message string The message to display in the terminal. name is used when this is undefined.
value string Value to associate with the choice. Useful for creating key-value pairs from user choices. name is used when this is undefined.
choices array Array of "child" choices.
hint string Help message to display next to a choice.
role string Determines how the choice will be displayed. Currently the only role supported is separator. Additional roles may be added in the future (like heading, etc). Please create a [feature request]
enabled boolean Enabled a choice by default. This is only supported when options.multiple is true or on prompts that support multiple choices, like MultiSelect.
disabled boolean|string Disable a choice so that it cannot be selected. This value may either be true, false, or a message to display.
indicator string|function Custom indicator to render for a choice (like a check or radio button).

❯ Key Bindings

Move/lock Pointer

command description
number Move the pointer to the choice at the given index. Also toggles the selected choice when options.multiple is true.
up Move the pointer up.
down Move the pointer down.
ctrl + a Move the pointer to the first visible choice.
ctrl + e Move the pointer to the last visible choice.
shift + up Scroll up one choice without changing pointer position (locks the pointer while scrolling).
shift + down Scroll down one choice without changing pointer position (locks the pointer while scrolling).

command (Mac) command (Windows) description
fn + left home Move the pointer to the first choice in the choices array.
fn + right end Move the pointer to the last choice in the choices array.

❯ About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Todo

We're currently working on documentation for the following items. Please star and watch the repository for updates!

  • Customizing symbols
  • Customizing styles (palette)
  • Customizing rendered input
  • Customizing returned values
  • Customizing key bindings
  • Question validation
  • Choice validation
  • Skipping questions
  • Async choices
  • Async timers: loaders, spinners and other animations
  • Links to examples

Autor

Frank Garcia

About

Un CLI para hacer peticiones a una API que devuelve datos sobre Articulos, Slides, e Imagenes de galeria

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published