$ box

   ______                                          ______
  / ____/___  ____ ___  ____ ___  ____ _____  ____/ / __ )____  _  __
 / /   / __ \/ __ `__ \/ __ `__ \/ __ `/ __ \/ __  / __  / __ \| |/_/
/ /___/ /_/ / / / / / / / / / / / /_/ / / / / /_/ / /_/ / /_/ />  <
\____/\____/_/ /_/ /_/_/ /_/ /_/\__,_/_/ /_/\__,_/_____/\____/_/|_| (R)  v5.2.1+00295

                            Talk is cheap. Show me the code. --Linus Torvalds

Welcome to CommandBox!
CommandBox>
# PRESENTING CODE

Writing Command Line Utilities With CommandBox Modules

By Abram Adams

Who Am I?

Developer, DevOps Engineer, Manager, etc...

Abram Adams

# TryCF

Also Built TryCF.com

  • Why CLI - GUI's are so easy 
  • CommandBox Modules
  • Development
  • CommandBox Ecosystem
  • Deploying CommandBox Modules

Key Takeaways

# Why Though?

Why CLI?

Reasons

1.

2.

3.

# Why Though?

Automation

Automation

Automation

  • Complements Other Tools
  • Adds Consistency Across Teams
  • Leverage Large Ecosystem
  • Simplifies Workflows/Tasks
  • Etc...

Many Others

# Why Though?

Makes You A Wizard

# Why Though?
  • CommandBox (CFML)
  • Oclif.io (JavaScript/TypeScript)
  • urfave/cli (Go)

  • spf13/cobra (Go)
  • Cement (Python)
  • .... endless others

CLI Frameworks

# CLI Frameworks
  • CommandBox (CFML)
  • Oclif.io (JavaScript/TypeScript)
  • urfave/cli (Go)

  • spf13/cobra (Go)
  • Cement (Python)
  • .... endless others

CLI Frameworks

# CLI Frameworks
  • Build your CLI in a language you already know
  • Leverage forgebox ecosystem
  • Pair with CommandBox docker images for CI/CD
  • Brad Wood

Why CommandBox?

# CLI Frameworks

{code}

Let's Look At Code

  • Interactive inputs
    • Free-form prompt
    • Confirmation (y/n)
    • Multiple choice
    • Hot-key

User Input

# CLI Inputs

{code}

Interactive Inputs

  • Make it DRY
  • Write it like any modern CFML

Helper Methods

# Helper Methods

{code}

Helper Methods

  • Run other CommandBox commands
  • Run shell commands
  • Run other binaries/executables
  • Full filesystem interaction

Running Commands & Filesystem Resources

# Modules/DI

{code}

Shell and Filesystem

  • Write and Inject Modules (ColdBox style)
  • Install external Modules

Modules/DI

# Modules/DI

{code}

Modules/Dependency Injection

  • Flags
  • CLI Arguments
  • Environment Variables

Arguments

# Arguments

{code}

Arguments - Automation

  • Automation
  • Security/Secrets
  • Consistent Configurations

Environment Variables

# Environment 

{code}

Environment Variables

  • Template config files
  • Template CF/YAML/JSON/etc..
  • Automation

Templating -

System Variable Expansion

# Templating

{code}

System Variable Expansion

# Create user (first time only)
forgebox register username password your@email.com firstName lastName
forgebox login username password

# Create package
mkdir mypackage --cd
package init slug=my-package type=modules
bump --major

# Publish it
publish

# Viewable and installable by the world!
forgebox show my-package
install my-package
# Publishing

Publishing Your CommandBox Module

  • aadams@cfxchange.com
  • abram   CFML Slack
  • github.com/abramadams

Thank You!

Writing Command Line Utilities with CommandBox Modules

By Abram Adams

Writing Command Line Utilities with CommandBox Modules

  • 249