Convert Figma logo to code with AI

c4spar logodeno-cliffy

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...

1,018
72
1,018
61

Top Related Projects

node.js command-line interfaces made easy

11,233

yargs the modern, pirate-themed successor to optimist.

9,153

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

16,300

Python composable command line interface toolkit

7,973

Create *beautiful* command-line interfaces with Python

Quick Overview

Deno Cliffy is a powerful command-line framework for Deno. It provides a comprehensive set of tools for building feature-rich CLI applications, including command parsing, prompts, tables, and more. Cliffy aims to simplify the process of creating complex command-line interfaces in Deno.

Pros

  • Extensive feature set, including command parsing, prompts, tables, and flags
  • Well-documented with clear examples and API references
  • Actively maintained and regularly updated
  • Designed specifically for Deno, leveraging its features and ecosystem

Cons

  • Limited to Deno environment, not usable in Node.js projects
  • Learning curve may be steeper for developers new to CLI frameworks
  • Dependency on Deno's ecosystem may limit portability to other JavaScript runtimes

Code Examples

  1. Creating a basic command:
import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .name("example")
  .version("1.0.0")
  .description("A simple example command")
  .action(() => console.log("Hello from Cliffy!"))
  .parse(Deno.args);
  1. Using prompts:
import { Input } from "https://deno.land/x/cliffy/prompt/mod.ts";

const name = await Input.prompt("What's your name?");
console.log(`Hello, ${name}!`);
  1. Creating a table:
import { Table } from "https://deno.land/x/cliffy/table/mod.ts";

new Table()
  .header(["Name", "Age"])
  .body([
    ["Alice", "24"],
    ["Bob", "32"],
  ])
  .render();

Getting Started

To use Cliffy in your Deno project, follow these steps:

  1. Import the desired modules from the Cliffy library:
import { Command } from "https://deno.land/x/cliffy/command/mod.ts";
import { Input } from "https://deno.land/x/cliffy/prompt/mod.ts";
  1. Create a new command or use other Cliffy features in your code:
const cli = new Command()
  .name("mycli")
  .version("1.0.0")
  .description("My CLI application")
  .action(async () => {
    const name = await Input.prompt("What's your name?");
    console.log(`Hello, ${name}!`);
  });

await cli.parse(Deno.args);
  1. Run your Deno script with the necessary permissions:
deno run --allow-read main.ts

Competitor Comparisons

node.js command-line interfaces made easy

Pros of Commander.js

  • Mature and widely adopted in the Node.js ecosystem
  • Extensive documentation and large community support
  • Supports both declarative and imperative command definitions

Cons of Commander.js

  • Limited to Node.js environment, not compatible with Deno
  • Less modern syntax compared to Cliffy
  • Fewer built-in features for advanced CLI development

Code Comparison

Commander.js:

const program = require('commander');

program
  .option('-d, --debug', 'output extra debugging')
  .option('-s, --small', 'small pizza size')
  .parse(process.argv);

Cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .option("-d, --debug", "output extra debugging")
  .option("-s, --small", "small pizza size")
  .parse(Deno.args);

Both libraries offer similar syntax for defining options, but Cliffy uses more modern ES module imports and async/await syntax. Commander.js relies on CommonJS require statements and synchronous parsing. Cliffy is designed specifically for Deno, while Commander.js is tailored for Node.js environments.

11,233

yargs the modern, pirate-themed successor to optimist.

Pros of yargs

  • Mature and widely adopted in the Node.js ecosystem
  • Extensive documentation and community support
  • Rich feature set, including command grouping and middleware support

Cons of yargs

  • Not designed for Deno, requiring additional setup or compatibility layers
  • Larger bundle size compared to Cliffy
  • Syntax can be more verbose for simple use cases

Code Comparison

yargs:

#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')

yargs(hideBin(process.argv))
  .command('serve [port]', 'start the server', (yargs) => {
    yargs.positional('port', {
      describe: 'port to bind on',
      default: 5000
    })
  }, (argv) => {
    console.log(`Server started on port ${argv.port}`)
  })
  .parse()

Cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .name("cli")
  .version("0.1.0")
  .description("Example CLI")
  .command("serve [port:number]", "Start the server")
  .action((options, port: number = 5000) => {
    console.log(`Server started on port ${port}`);
  })
  .parse(Deno.args);

Both libraries offer powerful CLI creation capabilities, but Cliffy is tailored for Deno, providing a more streamlined experience in that environment. yargs excels in the Node.js ecosystem with its extensive features and community support.

9,153

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

Pros of oclif

  • More mature and widely adopted, with a larger ecosystem and community support
  • Built-in plugin system for extending functionality
  • Comprehensive documentation and extensive examples

Cons of oclif

  • Requires Node.js runtime, limiting platform compatibility
  • Steeper learning curve due to more complex architecture
  • Heavier footprint and slower startup times compared to Deno-based alternatives

Code Comparison

oclif:

import {Command, flags} from '@oclif/command'

class MyCommand extends Command {
  static flags = {
    name: flags.string({char: 'n', description: 'name to print'})
  }

  async run() {
    const {flags} = this.parse(MyCommand)
    console.log(`Hello ${flags.name || 'world'}!`)
  }
}

cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .name("hello")
  .option("-n, --name <name:string>", "name to print")
  .action(({ name }) => {
    console.log(`Hello ${name || "world"}!`);
  })
  .parse(Deno.args);

Both oclif and cliffy offer powerful CLI development capabilities, but they cater to different ecosystems. oclif is more established in the Node.js world, while cliffy leverages Deno's modern features and simplicity. The choice between them largely depends on the target runtime environment and specific project requirements.

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Pros of Python Fire

  • Automatic CLI generation from Python functions and classes
  • Seamless integration with existing Python code
  • Extensive documentation and Google backing

Cons of Python Fire

  • Limited customization options for CLI appearance
  • Lack of built-in support for advanced features like subcommands

Code Comparison

Python Fire:

import fire

def hello(name="World"):
    return f"Hello {name}!"

if __name__ == '__main__':
    fire.Fire(hello)

Cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .name("hello")
  .option("-n, --name <name:string>", "Name to greet", { default: "World" })
  .action(({ name }) => console.log(`Hello ${name}!`))
  .parse(Deno.args);

Key Differences

  • Python Fire automatically generates CLI from existing functions, while Cliffy requires explicit CLI definition
  • Cliffy offers more granular control over command structure and options
  • Python Fire works with standard Python, while Cliffy is designed for Deno (TypeScript runtime)
16,300

Python composable command line interface toolkit

Pros of Click

  • Mature and well-established project with extensive documentation
  • Large ecosystem of extensions and plugins
  • Strong integration with Python's type hinting system

Cons of Click

  • Limited to Python development
  • Steeper learning curve for beginners
  • Requires more boilerplate code for complex CLI applications

Code Comparison

Click:

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
    for _ in range(count):
        click.echo(f"Hello, {name}!")

Cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .option("-c, --count <count:number>", "Number of greetings.", { default: 1 })
  .option("-n, --name <name:string>", "The person to greet.")
  .action(({ count, name }) => {
    for (let i = 0; i < count; i++) console.log(`Hello, ${name}!`);
  })
  .parse();

Both libraries offer similar functionality for creating CLI applications, but Cliffy is designed for Deno and TypeScript, while Click is Python-specific. Cliffy's syntax is more concise and modern, leveraging TypeScript's features, while Click relies on Python decorators and type hints.

7,973

Create *beautiful* command-line interfaces with Python

Pros of docopt

  • Simple and intuitive syntax based on usage patterns
  • Language-agnostic approach, available in multiple programming languages
  • Generates help messages automatically from the usage patterns

Cons of docopt

  • Less flexible for complex command-line interfaces
  • Limited support for advanced features like subcommands and nested options
  • Maintenance and updates are less frequent compared to more active projects

Code Comparison

docopt:

"""Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.
"""

Cliffy:

import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

await new Command()
  .name("naval_fate")
  .version("0.1.0")
  .description("Naval Fate CLI")
  .command("ship")
    .command("new <name:string>", "Create a new ship")
    .command("move <name:string> <x:number> <y:number>", "Move a ship")
      .option("-s, --speed <kn:number>", "Speed in knots", { default: 10 })
    .command("shoot <x:number> <y:number>", "Shoot at a position")
  .command("mine <action:string> <x:number> <y:number>", "Set or remove a mine")
    .option("--moored", "Moored (anchored) mine")
    .option("--drifting", "Drifting mine")
  .parse(Deno.args);

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Latest version popularity Build status Code coverage Discord

Cliffy is a simple and type-safe commandline framework for building complex commandline tools with deno.

Documentation

The documentation is available on cliffy.io.

Modules

  • ansi: Chainable ansi escape sequences.

  • command: Create complex and type-safe commandline tools with build-in input validation, auto generated help, shell completions and more.

  • flags: Parse command line arguments (used by the command module).

  • keycode: Parser ansi key codes.

  • keypress: Listen to keypress events with Promise, AsyncIterator and EventTarget APIs.

  • prompt: Create simple and powerful interactive prompts.

  • table: Create cli tables with border, padding, nested tables, etc...

  • testing: Helper functions for testing.

Contributing

Any kind of contribution is welcome! Please take a look at the contributing guidelines.

License

MIT