Rust

Power up CLI tools with natural language

Build a universal utility that transforms natural language tasks into precise command-line arguments.

⏱️ 2h 15min
📦 4 modules
🎯 Beginner

What You'll Build

You'll build an interactive command-line companion that turns plain-language requests into the exact arguments a tool expects. Ask it to undo your last commit and it will surface git reset --soft HEAD^, ready to run.

It runs as a universal wrapper you can call alongside your usual commands (for example, git+ drop the last commit) and always shows a clear preview for confirmation, so actions stay safe and deliberate.

Learning Objectives

  • Build a CLI that leverages LLM prompts

  • Implement robust argument parsing and path handling

  • Integrate rig-core with the tokio runtime

  • Create robust error handling with anyhow

  • Add friendly confirmations using dialoguer

  • Execute external commands and handle exit codes

Prerequisites

  • Basic Rust syntax and ownership

  • Basic command-line experience

  • Familiarity with async/await concepts

  • Rust and cargo installed

  • OpenAI API key

Course Modules

1

Parsing inputs

Create a binary crate and configure anyhow for ergonomic errors. Parse command-line args, extract the real command, and build natural_args.

2

Interacting with a model

Create a prompt template with role, task, placeholders, and constraints. Wire it to rig-core and tokio for async requests.

3

Running a command

Request user confirmation with dialoguer, then execute the composed command.
Run commands via tokio process, forward I/O, and handle exit codes.

4

Testing the agent

Build the release binary, install it to ~/.local/bin, and create an alias. Set OPENAI_API_KEY, then run git+ to suggest precise git commands.

Technologies

Rust CLI clap OpenAI rig-core tokio