Skip to content

Commit

Permalink
feat: generate powerpoint command
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 21, 2025
1 parent a1a4bd1 commit a90b2c0
Show file tree
Hide file tree
Showing 11 changed files with 948 additions and 580 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log (go-package-manager)

## 0.36.0

- **BREAKING CHANGE**: `AppContext.CreateAIChat()` now uses initial value from `--system-prompt` flag
- feat: `generate powerpoint` command, which generates PowerPoint `.pptx` file from files using AI
- refactor: code cleanups and improvements

## 0.35.1

- **BREAKING CHANGE**: `generate guid` => `guid`/`uuid`
Expand Down
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- [Encoding](#encoding-)
- [Execute shell command](#execute-shell-command-)
- [Generate documentation](#generate-documentation-)
- [Generate PowerPoint](#generate-powerpoint-)
- [Generate project](#generate-project-)
- [Import aliases](#import-aliases-)
- [Import projects](#import-projects-)
Expand Down Expand Up @@ -340,6 +341,18 @@ To output the documentation into a specific folder, use:
gpm generate documentation my-doc-folder
```

#### Generate PowerPoint [<a href="#commands-">↑</a>]

The following command will execute the default command template `pandoc -t pptx -o "{{.OutputFile}}" "{{.InputFile}}"` by creating `out.pptx` file from Markdown code, saved into `{{.InputFile}}`, which will be generated by AI:

```bash
gpm generate powerpoint out.pptx my-text-file1.txt *.go README.md --language=german
```

In this case [Pandoc](https://pandoc.org/) must be installed on your system.

You can change the template by using `--template` flag or `GPM_GENERATE_PPTX_FROM_MD_COMMAND` environment variable, if you want to use another command.

#### Generate project [<a href="#commands-">↑</a>]

To generate a new Go project tailored to your requirements, execute the following command:
Expand Down Expand Up @@ -787,25 +800,26 @@ Environment variables can be loaded from external files, which are handled in th

### Supported variables [<a href="#environment-variables-">↑</a>]

| Name | Description | Example |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `GPM_AI_API` | ID of the AI API to use. Possible values are `ollama` or `openai`. | `openai` |
| `GPM_AI_CHAT_MODEL` | ID of the AI chat model to use. Possible values are models by [OpenAI](https://platform.openai.com/docs/models) or [Ollama](https://ollama.com/library). | `gpt-4o` |
| `GPM_AI_CHAT_TEMPERATURE` | Temperature value for an AI chat (operation) | `0` |
| `GPM_AI_PROMPT` | Custom prompt for operations which are using chat completion operations, like [checkout command](#build-project-). | |
| `GPM_AI_SYSTEM_PROMPT` | Custom (initial) system prompt for AI chat operations. | `You are a helpful AI assistant. You always answer in a very sarcastic way.` |
| `GPM_ALIASES_FILE` | Custom path to [aliases.yaml file](#add-alias-). Relative paths will be mapped to `<GPM-ROOT>`. Default is `<GPM-ROOT>/aliases.yaml`. | `/my/custom/aliases/file.yaml` |
| `GPM_BIN_PATH` | Custom folder for binaries installed by [make command](#build-and-install-executable-). Default is `<GPM-ROOT>/bin`. | `/my/custom/bin/path` |
| `GPM_DOWN_COMMAND` | Custom command for [docker compose down](#docker-shorthands-) shorthand. | `docker-compose down` |
| `GPM_ENV` | ID of the current environment. This is especially used for the [.env files](#environment-variables-). | `prod` |
| `GPM_INSTALL_PATH` | Custom installation path of global `gpm` binary. | `/usr/bin` |
| `GPM_PROJECTS_FILE` | Custom path to [projects.yaml file](#add-project-). Relative paths will be mapped to `<GPM-ROOT>`. Default is `<GPM-ROOT>/projects.yaml`. | `/my/custom/projects/file.yaml` |
| `GPM_ROOT_BASE_PATH` | Custom root base folder for this application. Relative paths will be mapped to `$HOME`. Default is `$HOME/.gpm`. | `.my-gpm-folder-inside-home` |
| `GPM_TERMINAL_FORMATTER` | Default formatter for syntax highlighting in terminal. See [chroma project](https://github.com/alecthomas/chroma/tree/master/formatters) for more information. | `terminal16m` |
| `GPM_TERMINAL_STYLE` | Default style for syntax highlighting in terminal. See [chroma project](https://github.com/alecthomas/chroma/tree/master/styles) for more information. | `monokai` |
| `GPM_UP_COMMAND` | Custom command for [docker compose up](#docker-shorthands-) shorthand. | `docker-compose up` |
| `GPM_UPDATE_SCRIPT` | Custom URL to self-update script | `sh.kloubert.dev/gpm.sh` |
| `OPENAI_API_KEY` | Key which is used for the [API by OpenAI](https://platform.openai.com/docs/api-reference). | `sk-...` |
| Name | Description | Example |
| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `GPM_AI_API` | ID of the AI API to use. Possible values are `ollama` or `openai`. | `openai` |
| `GPM_AI_CHAT_MODEL` | ID of the AI chat model to use. Possible values are models by [OpenAI](https://platform.openai.com/docs/models) or [Ollama](https://ollama.com/library). | `gpt-4o` |
| `GPM_AI_CHAT_TEMPERATURE` | Temperature value for an AI chat (operation) | `0` |
| `GPM_AI_PROMPT` | Custom prompt for operations which are using chat completion operations, like [checkout command](#build-project-). | |
| `GPM_AI_SYSTEM_PROMPT` | Custom (initial) system prompt for AI chat operations. | `You are a helpful AI assistant. You always answer in a very sarcastic way.` |
| `GPM_ALIASES_FILE` | Custom path to [aliases.yaml file](#add-alias-). Relative paths will be mapped to `<GPM-ROOT>`. Default is `<GPM-ROOT>/aliases.yaml`. | `/my/custom/aliases/file.yaml` |
| `GPM_BIN_PATH` | Custom folder for binaries installed by [make command](#build-and-install-executable-). Default is `<GPM-ROOT>/bin`. | `/my/custom/bin/path` |
| `GPM_DOWN_COMMAND` | Custom command for [docker compose down](#docker-shorthands-) shorthand. | `docker-compose down` |
| `GPM_ENV` | ID of the current environment. This is especially used for the [.env files](#environment-variables-). | `prod` |
| `GPM_GENERATE_PPTX_FROM_MD_COMMAND` | Template for a command that generates a PowerPoint presentation from a Markdown file. | `pandoc -t pptx -o "{{.OutputFile}}" "{{.InputFile}}` |
| `GPM_INSTALL_PATH` | Custom installation path of global `gpm` binary. | `/usr/bin` |
| `GPM_PROJECTS_FILE` | Custom path to [projects.yaml file](#add-project-). Relative paths will be mapped to `<GPM-ROOT>`. Default is `<GPM-ROOT>/projects.yaml`. | `/my/custom/projects/file.yaml` |
| `GPM_ROOT_BASE_PATH` | Custom root base folder for this application. Relative paths will be mapped to `$HOME`. Default is `$HOME/.gpm`. | `.my-gpm-folder-inside-home` |
| `GPM_TERMINAL_FORMATTER` | Default formatter for syntax highlighting in terminal. See [chroma project](https://github.com/alecthomas/chroma/tree/master/formatters) for more information. | `terminal16m` |
| `GPM_TERMINAL_STYLE` | Default style for syntax highlighting in terminal. See [chroma project](https://github.com/alecthomas/chroma/tree/master/styles) for more information. | `monokai` |
| `GPM_UP_COMMAND` | Custom command for [docker compose up](#docker-shorthands-) shorthand. | `docker-compose up` |
| `GPM_UPDATE_SCRIPT` | Custom URL to self-update script | `sh.kloubert.dev/gpm.sh` |
| `OPENAI_API_KEY` | Key which is used for the [API by OpenAI](https://platform.openai.com/docs/api-reference). | `sk-...` |

## Contribution [<a href="#table-of-contents">↑</a>]

Expand Down
96 changes: 96 additions & 0 deletions commands/generate.documentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package commands

import (
"strings"

"github.com/mkloubert/go-package-manager/types"
"github.com/mkloubert/go-package-manager/utils"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

func init_generate_documentation_command(parentCmd *cobra.Command, app *types.AppContext) {
var man bool
var markdown bool
var rest bool
var yaml bool

var documentationCmd = &cobra.Command{
Use: "documentation [resource]",
Aliases: []string{"doc", "docs", "dox"},
Short: "Generate documentation",
Long: `Generate documentation into the current directory.`,
PreRun: func(cmd *cobra.Command, args []string) {
if !man && !markdown && !rest && !yaml {
app.Debug("Setting 'markdown' as default format ...")

// default is Markdown
markdown = true
}
},
Run: func(cmd *cobra.Command, args []string) {
outDir := app.Cwd
if len(args) > 0 {
outDir = strings.TrimSpace(args[0])
}

outDir, err := app.EnsureFolder(outDir)
utils.CheckForError(err)

// collect generators by flags
generators := make([]func(), 0)
if man {
// man pages
generators = append(generators, func() {
app.Debug("Generating man pages in", outDir, "...")

header := doc.GenManHeader{}

err := doc.GenManTree(cmd.Root(), &header, outDir)
utils.CheckForError(err)
})
}
if markdown {
// Markdown files
generators = append(generators, func() {
app.Debug("Generating Markdown files in", outDir, "...")

err := doc.GenMarkdownTree(cmd.Root(), outDir)
utils.CheckForError(err)
})
}
if rest {
// ReST files
generators = append(generators, func() {
app.Debug("Generating ReST files in", outDir, "...")

err := doc.GenReSTTree(cmd.Root(), outDir)
utils.CheckForError(err)
})
}
if yaml {
// YAML files
generators = append(generators, func() {
app.Debug("Generating YAML files in", outDir, "...")

err := doc.GenYamlTree(cmd.Root(), outDir)
utils.CheckForError(err)
})
}

// execute generators
for _, generate := range generators {
generate()
}
},
}

documentationCmd.Flags().BoolVarP(&man, "man", "", false, "generate man pages")
documentationCmd.Flags().BoolVarP(&markdown, "markdown", "m", false, "generate Markdown files")
documentationCmd.Flags().BoolVarP(&rest, "rest", "r", false, "generate ReST files")
documentationCmd.Flags().BoolVarP(&yaml, "yaml", "y", false, "generate YAML files")

parentCmd.AddCommand(
documentationCmd,
)
}
Loading

0 comments on commit a90b2c0

Please sign in to comment.