Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.15 KB

File metadata and controls

42 lines (34 loc) · 1.15 KB

Day 13: Building CLI Tools

Overview

This day focuses on Building CLI Tools in Go. You will learn how to create command-line tools using Go and explore libraries like cobra and urfave/cli.

Tasks

  • Task 1: Create a basic CLI tool using Go's flag package.
  • Task 2: Use the cobra library to build a more advanced CLI tool.
  • Task 3: Add subcommands and flags to your CLI tool.

Resources

Example Code

// Example: Basic CLI Tool with Cobra
package main

import (
    "fmt"
    "github.com/spf13/cobra"
)

func main() {
    var rootCmd = &cobra.Command{
        Use:   "mycli",
        Short: "MyCLI is a simple CLI tool",
        Run: func(cmd *cobra.Command, args []string) {
            fmt.Println("Hello from MyCLI!")
        },
    }

    rootCmd.Execute()
}

Exercises

  • Build a CLI tool that accepts user input and performs a simple task (e.g., file renaming).
  • Use the cobra library to add subcommands to your CLI tool.
  • Implement flags and arguments for your CLI tool.