Logo

Programming-Idioms

Print "verbose is true" if the flag -v was passed to the program command line, "verbose is false" otherwise.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
print("verbose is ${args.contains("-v")}");
import "flag"
var verbose = flag.Bool("v", false, "verbose")
flag.Parse()
fmt.Println("verbose is", *verbose)
const verbose = process.argv.includes('-v');
console.log('verbose is', verbose);
import static java.lang.System.out;
public static void main(String[] args) {
    boolean b = false;
    for (String s : args)
        if (s.equals("-v")) {
            b = true;
            break;
        }
    out.printf("verbose is %s", b);
}
for i in paramcount do
begin
  if paramstr(i)='-v' then 
  begin
    verbose := true;
    break;
  end;
 writeln('verbose is ',verbose);
end.
#!/usr/bin/perl -s

use strict;
use warnings;
use vars qw($v);

$v ||= 0;

print 'verbose is ' . ($v ? 'true' : 'false') . "\n";
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-v', action='store_true', dest='verbose')
args = parser.parse_args()
print('verbose is', args.verbose)
from sys import argv
print('verbose is', '-v' in argv[1:])
use clap::{Arg, App};
let matches = App::new("My Program")
                .arg(Arg::with_name("verbose")
                    .short("v")
                    .takes_value(false))
                .get_matches();
                   
if matches.is_present("verbose") {
    println!("verbose is true")
} else {
    println!("verbose is false")
}