Skip to content

Commit

Permalink
feat: environment specific sections and more custom paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 5, 2025
1 parent a16f7e7 commit 4615df0
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 83 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log (go-package-manager)

## 0.32.0

- **BREAKING CHANGE**: when an environment is defined, the root base path of the application changes from `${HOME}/.gpm` to the specified path
- **BREAKING CHANGE**: with the introduction of the `GPM_ROOT_BASE_PATH` environment variable, `.env.{ENV-SUFFIX}` files are no longer supported ... these files must be moved or merged into the corresponding environment subfolder, like `${HOME}/.gpm/<ENV-NAME>`, as `.env`
- **BREAKING CHANGE**: Scripts in the `gpm.yaml` file with an environment prefix (e.g., `dev:build` for a `dev` environment) will now execute instead of their unprefixed counterparts (e.g., `build`)
- feat: added support for the `GPM_ROOT_BASE_PATH` environment variable
- feat: you can now define a custom `files` section with an environment suffix in the `gpm.yaml` file (e.g., `files:dev` for a `dev` environment)
- feat: can define custom path to `aliases.yaml` file by `GPM_ALIASES_FILE` environment variable
- feat: can define custom path to `projects.yaml` file by `GPM_PROJECTS_FILE` environment variable

## 0.31.0

- feat: `generate password` command
Expand Down
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ With
gpm add alias yaml https://github.com/go-yaml/yaml
```

you define the alias `yaml` which refers to the Git repository in `https://github.com/go-yaml/yaml`. This information will be stored in `aliases.yaml` file inside your `$HOME/.gpm` folder.
you define the alias `yaml` which refers to the Git repository in `https://github.com/go-yaml/yaml`. This information will be stored in `aliases.yaml` file inside your `<GPM-ROOT>` folder.

If you later run

Expand All @@ -154,7 +154,7 @@ With
gpm add project react-project https://github.com/ofnullable/react-spa-template
```

you define the alias `react-project` which refers to the Git repository in `https://github.com/ofnullable/react-spa-template`. This information will be stored in `projects.yaml` file inside your `$HOME/.gpm` folder.
you define the alias `react-project` which refers to the Git repository in `https://github.com/ofnullable/react-spa-template`. This information will be stored in `projects.yaml` file inside your `<GPM-ROOT>` folder.

If you later run

Expand All @@ -180,7 +180,7 @@ gpm make https://github.com/gohugoio/hugo

will clone the repository into a temp folder and run `gpm build` from it.

The final executable will be installed in `$HOME/.gpm/bin` folder. So it could be useful to add it to the `$PATH` enviornment variable.
The final executable will be installed in `<GPM-ROOT>/bin` folder. So it could be useful to add it to the `$PATH` enviornment variable.

FYI: Instead of the URL as argument you can use a project alias added by [add project command](#add-project-).

Expand Down Expand Up @@ -333,7 +333,7 @@ gpm generate uuid
gpm import aliases https://raw.githubusercontent.com/mkloubert/go-package-manager/main/aliases.yaml
```

loads aliases from `https://raw.githubusercontent.com/mkloubert/go-package-manager/main/aliases.yaml` and merge them with entries in `aliases.yaml` file in `$HOME/.gpm` folder.
loads aliases from `https://raw.githubusercontent.com/mkloubert/go-package-manager/main/aliases.yaml` and merge them with entries in `aliases.yaml` file in `<GPM-ROOT>` folder.

You can also use a local file path and/or pipe from `STDIN` as well.

Expand All @@ -343,7 +343,7 @@ You can also use a local file path and/or pipe from `STDIN` as well.
gpm import projects https://raw.githubusercontent.com/mkloubert/go-package-manager/main/projects.yaml
```

loads projects from `https://raw.githubusercontent.com/mkloubert/go-package-manager/main/projects.yaml` and merge them with entries in `projects.yaml` file in `$HOME/.gpm` folder.
loads projects from `https://raw.githubusercontent.com/mkloubert/go-package-manager/main/projects.yaml` and merge them with entries in `projects.yaml` file in `<GPM-ROOT>` folder.

You can also use a local file path and/or pipe from `STDIN` as well.

Expand Down Expand Up @@ -497,7 +497,7 @@ With
gpm remove alias yaml
```

you will remove the `yaml` alias from `aliases.yaml` file, which is stored in `$HOME/.gpm` folder.
you will remove the `yaml` alias from `aliases.yaml` file, which is stored in `<GPM-ROOT>` folder.

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

Expand All @@ -507,7 +507,7 @@ With
gpm remove project yaml
```

you will remove the `yaml` alias from `projects.yaml` file, which is stored in `$HOME/.gpm` folder.
you will remove the `yaml` alias from `projects.yaml` file, which is stored in `<GPM-ROOT>` folder.

#### Remove executable [<a href="#commands-">↑</a>]

Expand All @@ -517,7 +517,7 @@ If you installed a binary with [make command](#build-and-install-executable-) li
gpm make https://github.com/gopasspw/gopass
```

you can simply remove it with `gpm remove binary gopass` if the binary is stored as `gopass` in `$HOME/.gpm/bin` folder.
you can simply remove it with `gpm remove binary gopass` if the binary is stored as `gopass` in `<GPM-ROOT>/bin` folder.

#### Run script [<a href="#commands-">↑</a>]

Expand Down Expand Up @@ -651,7 +651,7 @@ in your terminal.

### Files [<a href="#gpmyaml-">↑</a>]

The `files` section contains a list of regular expressions of files which is used by [pack command](#pack-project-):
The `files` section contains a list of regular expressions that specify which files are included by the [pack command](#pack-project-):

```yaml
# ...
Expand All @@ -664,26 +664,50 @@ files:
# ...
```

If the list is empty or not defined, the following default values are set:
If the list is empty or not defined, the following default values are applied:

- possible name of the executable file build with [build command](#build-project-)
- the potential name of the executable file built with the [build command](#build-project-)
- `^CHANGELOG.md$`
- `^CONTRIBUTING.md$`
- `^CONTRIBUTION.md$`
- `^LICENSE$`
- `^README.md$`

You can also define environment-specific file lists to customize behavior for different environments:

```yaml
# ...

"files:dev":
- my-dev-app
- README.dev.md
- ^commands/p
# ...
```

When `files:dev` is defined, it takes precedence over the `files` list, allowing you to tailor the included files for specific environments.

### Scripts [<a href="#gpmyaml-">↑</a>]

Create or update the `scripts` section with key/value pairs:
To configure your scripts, add or update the `scripts` section with key/value pairs as shown below:

```yaml
scripts:
test1: "echo Test1"
test2: "echo Test2"
```
From the project folder you will be able to execute `gpm run test1` or `gpm run test2` to run the defined shell/terminal commands.
Once defined, you can run the commands directly from your project folder using `gpm run test1` or `gpm run test2`.

You can also create environment-specific scripts to customize behavior for different environments:

```yaml
scripts:
test1: "echo Test1 runs in the default environment"
dev:test1: "echo Test1 runs in the 'dev' environment"
```

When executing `gpm run test1 --environment=dev`, the command will prioritize `dev:test1` over `test1`. This allows you to tailor scripts for specific environments easily.

#### Predefined [<a href="#scripts-">↑</a>]

Expand All @@ -703,7 +727,7 @@ From the project folder you will be able to execute `gpm run test1` or `gpm run

Environment variables can be loaded from external files, which are handled in this order:

- `$HOME/.gpm/.env<SUFFIX>` (if exist)
- `<GPM-ROOT>/.env` (if exist)
- `<PROJECT-DIR>/.env` (if exist)
- `<PROJECT-DIR>/.env<SUFFIX>` (if exist)
- `<PROJECT-DIR>/.env.local` (if exist)
Expand All @@ -721,10 +745,13 @@ Environment variables can be loaded from external files, which are handled in th
| `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_BIN_PATH` | Custom folder for binaries installed by [make command](#build-and-install-executable-). Default is `$HOME/.gpm/bin`. | `/my/custom/bin/path` |
| `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` |
Expand Down
8 changes: 4 additions & 4 deletions commands/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Init_Make_Command(parentCmd *cobra.Command, app *types.AppContext) {
func() {
app.Debug(fmt.Sprintf("Will make project from '%v' ...", gitResource))

// get `$HOME/.gpm/bin` folder
// get `<GPM-ROOT>/bin` folder
binPath, err := app.EnsureBinFolder()
utils.CheckForError(err)

Expand Down Expand Up @@ -132,7 +132,7 @@ func Init_Make_Command(parentCmd *cobra.Command, app *types.AppContext) {
if executableNameInBinFolder == "" {
// use project name as default for the
// name of the final executable file in
// ${HOME}/.gpm/bin folder
// <GPM-ROOT>/bin folder
executableNameInBinFolder = projectName
}

Expand All @@ -146,12 +146,12 @@ func Init_Make_Command(parentCmd *cobra.Command, app *types.AppContext) {
os.Remove(executableFileInBinFolder)
}

// move build executable to ${HOME}/.gpm/bin folder
// move build executable to <GPM-ROOT>/bin folder
app.Debug(fmt.Sprintf("Moving build executable '%v' to '%v' ...", buildExecutableFilePath, executableFileInBinFolder))
err = os.Rename(buildExecutableFilePath, executableFileInBinFolder)
utils.CheckForError(err)

// make file in ${HOME}/.gpm/bin folder executable
// make file in <GPM-ROOT>/bin folder executable
app.Debug(fmt.Sprintf("Setting up permissions for '%v' executable ...", executableFileInBinFolder))
err = os.Chmod(executableFileInBinFolder, constants.DefaultDirMode)
utils.CheckForError(err)
Expand Down
2 changes: 2 additions & 0 deletions gpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ files:
scripts:
docs: "go run . generate documentation ./docs"
test: "exit 0"
test1: "echo test1 runs on default environment"
dev:test1: "echo test1 runs on 'dev' environment"
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@ func main() {
app.Cwd = cwd
app.IsCI = strings.TrimSpace(strings.ToLower(os.Getenv("CI"))) == "true"

// use "aliases-file flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.AliasesFilePath, "aliases-file", "", "", "custom aliases file")
// use "environment flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.Environment, "environment", "", "", "name of the environment")
// use "env-file flag" everywhere
rootCmd.PersistentFlags().StringArrayVarP(&app.EnvFiles, "env-file", "e", []string{}, "one or more environment files")
// use "gpm-root flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.GpmRootPath, "gpm-root", "", "", "custom root directory for this app")
// use "no-system-prompt flag" everywhere
rootCmd.PersistentFlags().BoolVarP(&app.NoSystemPrompt, "no-system-prompt", "", false, "do not use system prompt")
// use "ollama flag" everywhere
rootCmd.PersistentFlags().BoolVarP(&app.Ollama, "ollama", "", false, "use Ollama")
// use "prompt flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.Prompt, "prompt", "", "", "custom (AI) prompt")
// use "projects-file flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.ProjectsFilePath, "projects-file", "", "", "custom projects file")
// use "system-prompt flag" everywhere
rootCmd.PersistentFlags().StringVarP(&app.SystemPrompt, "system-prompt", "", "", "custom (AI) system prompt")
// use "verbose flag" everywhere
Expand Down
Loading

0 comments on commit 4615df0

Please sign in to comment.