Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
How i print a number in caporal js

I want to print a number in caporal js. But the result not i want because return true/false. I want to if not exist passing a parameter number,default value is 32. This is my code


#!/usr/bin/env node
const { program } = require("@caporal/core");

program

  .command("random", "Generate random alphanumeric")
  .option("--length", "length of number", program.NUMERIC, 32)
  .action(({ logger, args, options }) => {
    let length = options.length;
    let letters = options.letters
    logger.info(length);
  });

program.run();

if i run on terminal

let say

./app.js random

will be result 32

if i run ./app.js random --length=10

will be result 10

i have tried found the problem, but i cant. How i must repair my code so appropriated with i want?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use this code:

#!/usr/bin/env node
const { program } = require("@caporal/core");

program

  .command("random", "Generate random alphanumeric")
  .option("--length <num>", "length of number", {
    validator: program.NUMBER,
    default: 32,
  })
  .action(({ logger, args, options }) => {
    let length = options.length;
    let letters = options.letters
    logger.info(length);
  });

program.run();

options in .option there are 3 arguments, including:

  1. Option synopsis is a string like '-f, --force', or '-f, --file <file>', or '--with-openssl [path]'
  2. Option description in the form of a string
  3. Options Additional parameters containing the custom command options

You can change --length to --length <num> to add the number value after the --length command. Then, you remove program.NUMERIC, 32 and add this code

{
     validator: program.NUMBER,
     defaults: 32,
}

to define a validator into the number data type and contains the default number is 32.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!