Skip to content

paiml/rust-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust CLI Tools for Data Engineering

This repository contains hands-on examples and labs for building command-line tools with Rust for data engineering tasks. A Coursera course from Pragmatic AI Labs.

Contents

This repository has example projects in ./examples and hands-on labs in ./labs. Make sure you have the Rust toolchain installed.

This repository is Codespaces ready and set as a template repository. You can open it directly in a GitHub Codespace — Rust, rust-analyzer, and all extensions are pre-installed.

Open in GitHub Codespaces

Labs

Complete these hands-on labs to reinforce your learning:

Lab Topic Example
Lab 1: Your First CLI in Rust std::env args, reading files, basic error handling examples/1-first-cli
Lab 2: Using clap for Argument Parsing clap derive API, named flags, help generation examples/2-clap-intro
Lab 3: Organizing Code with Modules mod, pub, separating business logic from main examples/3-modules
Lab 4: Multi-Subcommand CLI Design Subcommand derive, dispatch with match examples/4-subcommands
Lab 5: Complex Argument Types ValueEnum, Option, --limit, Box examples/5-complex-args
Lab 6: Environment Variables #[arg(env)], layered config, directory filtering examples/6-env-vars
Lab 7: Logging env_logger, RUST_LOG, info/warn/debug/error examples/7-logging
Lab 8: Error Handling with anyhow anyhow::Result, ?, bail!, ensure!, with_context examples/8-error-handling

Course Outline

Module 1: CLI Foundations

Lesson 1.1 — Your First CLI in Rust

Lesson 1.2 — Modules and Dependencies

Module 2: Building Production-Ready CLIs

Lesson 2.1 — Subcommands and Advanced Arguments

Lesson 2.2 — Packaging and Distribution

  • Creating a publishable Rust package
  • Releasing to crates.io
  • Containerizing a Rust CLI with Docker

Lesson 2.3 — Logging and Error Handling

Module 3: Course Conclusion

Wrapping up the course and next steps in the Rust for Data Engineering specialization.

Graded Project: datactl

Build datactl — a Rust CLI tool for data engineering tasks that reads CSV and JSON files and supports these subcommands:

  • read <file> — load a CSV or JSON file and show row count and column names
  • summary <file> — compute per-column aggregate statistics (count, min, max)
  • filter <file> --column <name> --value <val> — print rows where the column matches the value
  • export <file> --format csv|json [--output <path>] — convert between CSV and JSON formats

A starter implementation is in datactl/.

# Build
cargo build -p datactl

# Read a file
cargo run -p datactl -- read data.csv

# Summarize statistics
cargo run -p datactl -- summary data.csv

# Filter rows
cargo run -p datactl -- filter data.csv --column region --value west

# Export to JSON
cargo run -p datactl -- export data.csv --format json --output data.json

# Export to stdout
cargo run -p datactl -- export data.json --format csv

Local Setup

  1. Install the Rust toolchain:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. Clone this repository:

    git clone https://github.com/alfredodeza/rust-cli.git
    cd rust-cli
  3. Build the entire workspace:

    cargo build --workspace
  4. Run an example:

    cargo run -p first-cli -- Cargo.toml
  5. Run a subcommand example:

    cargo run -p subcommands -- stats Cargo.toml

Key Crates

Crate Purpose
clap CLI argument parsing with the derive API
serde / serde_json JSON serialization and deserialization
csv CSV reading and writing
anyhow Ergonomic error propagation
log / env_logger Structured logging controlled by RUST_LOG

Resources

Coursera Courses

About

Learn how to work with Rust to create powerful command line tools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages