Javascript
Getting Started with Deno — Hands On

Command Line Flags Solution

PRO
Outline

Here's one solution for this assignment:

// command-line-flags.ts
const { args } = Deno;
import { parse } from 'https://deno.land/std/flags/mod.ts';
const parsedArgs = parse(args);

const name = parsedArgs.name || 'Friend';

console.log(`Welcome, ${name}`);

Here's the result of running the command with and without a flag:

deno run command-line-flags.ts --name Preston
Welcome, Preston

deno run command-line-flags.ts
Welcome, Friend
 

I finished! On to the next chapter