Table of Content
In this section, you will find examples of how to use the ai command line program.
$ ai --new Write a Go program that counts the number of lines in a file passed using command line.
Sure, here's a short Go program that does that:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <file>\n", os.Args[0])
os.Exit(1)
}
(...)
In this program, os.Args provides command line arguments. It first checks
whether exactly one argument (the file name) is provided. Then, it opens the
file and counts the lines using a scanner. If any errors occur (like the
file not existing), it reports these on the standard error output.
$ ai Update the program so it also counts the number of characters.
Certainly, I would add another variable to keep a track of the characters.
Each time a line is read, its length in terms of characters can be easily
added. Here's the updated code:
package main
(...)
$ ai --new --inline README.md Summarize the following document:
$ ai --list
• ba91b74 Summarize following document:
• 74b3901 Write a Go program that counts number of lines in a file passed ...
$ ai --convo 74b3 "Update the program, so that it also counts words"
Sure, here's the updated Go program that counts both the number of lines and
words in a given file:
package main
(...)
$ ai --regenerate
$ ai --regenerate --edit
$ git diff | ai --new --edit "Summarize following changes:"
$ ai --new --model gpt-3.5-turbo Tell me a joke.
$ ai --delete 9d1d510
$ ai --show
$ ai --show 5 --convo 74b3901
$ ai --show 0
$ ai --show-all
$ ai --show --fmt raw
For a comprehensive reference of the command line interface for the ai
program, please refer to the “CLI
Reference” chapter.