Skip to content

Commit

Permalink
Ability to pass options as environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
srozange committed Sep 9, 2023
1 parent c55512b commit 890c3ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
38 changes: 15 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,26 @@ You can check their [readme page](https://github.com/yaml-path/YamlPath) for the

## Manual
```bash
Usage: yupd [-hV] [--dry-run] [--pull-request] [--verbose] -b=<branch>
[-f=<sourceFile>] [-m=<message>] -p=<path> --project=<project>
[-r=<url>] --repo-type=<repoType> -t=<token> --set=<String=String>
[--set=<String=String>]...
-b, --branch=<branch> Specifies the branch name of the target file to
update
--dry-run If set to true, no write operation is done
Usage: yupd [-hV] [--dry-run] [--pull-request] [--verbose] -b=<branch> [-f=<sourceFile>] [-m=<commitMessage>] -p=<path> --project=<project> [-r=<url>]
--repo-type=<repoType> [-t=<token>] --set=<String=String> [--set=<String=String>]...
-b, --branch=<branch> Specifies the branch name of the target file to update (env: YUPD_BRANCH)
--dry-run If set to true, no write operation is done (env: YUPD_DRY_RUN)
-f, --template=<sourceFile>
Points to a local YAML file to be used as the
source, instead of the remote one
Points to a local YAML file to be used as the source, instead of the remote one (env: YUPD_TEMPLATE)
-h, --help Show this help message and exit.
-m, --commit-msg=<commitMessage>
Provides a custom commit message for the update
-p, --path=<path> Specifies the path of the target file to update
--project=<project> Identifies the project (e.g., 'srozange/yupd' for
GitHub or '48539100' for GitLab)
Provides a custom commit message for the update (env: YUPD_COMMIT_MSG)
-p, --path=<path> Specifies the path of the target file to update (env: YUPD_PATH)
--project=<project> Identifies the project (e.g., 'srozange/yupd' for GitHub or '48539100' for GitLab) (env: YUPD_PROJECT)
--pull-request, --merge-request
If set to true, open either a pull request or a
merge request based on the Git provider context
-r, --repo=<url> Specifies the URL of the Git gitRepository
If set to true, open either a pull request or a merge request based on the Git provider context (env: YUPD_MERGE_REQUEST)
-r, --repo=<url> Specifies the URL of the Git repository (env: YUPD_REPO)
--repo-type=<repoType>
Specifies the gitRepository type; valid values:
'gitlab' or 'github'
--set=<String=String> Allows setting YAML path expressions (e.g.,
metadata.name=new_name)
-t, --token=<token> Provides the authentication token
Specifies the repository type; valid values: 'gitlab' or 'github' (env: YUPD_REPO_TYPE)
--set=<String=String> Allows setting YAML path expressions (e.g., metadata.name=new_name) (env: YUPD_SET)
-t, --token=<token> Provides the authentication token (env: YUPD_TOKEN)
-V, --version Print version information and exit.
--verbose If set to true, sets the log level to debug
--verbose If set to true, sets the log level to debug (env: YUPD_VERBOSE)
```

## Installation
Expand All @@ -101,7 +93,7 @@ Docker images are available on [Docker Hub](https://hub.docker.com/gitRepository
To use the image, you can run the following command:

```bash
docker run srozange/yupd:0.2 --repo-type github --token <token> ...
docker run --rm srozange/yupd:0.2 --repo-type github --token <updateme> --project srozange/playground --path k8s/deployment.yml --branch yupd-it --set *.containers[0].image=nginx:newversion
```

## Limitations
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/io/github/yupd/command/YupdCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@
import java.util.Map;
import java.util.concurrent.Callable;

@CommandLine.Command(name = "yupd", mixinStandardHelpOptions = true, versionProvider = YupdVersionProvider.class)
@CommandLine.Command(name = "yupd", mixinStandardHelpOptions = true, versionProvider = YupdVersionProvider.class, usageHelpWidth = 160)
public class YupdCommand implements Callable<Integer> {

private final YamlRepoUpdater yamlRepoUpdater;

@CommandLine.Option(names = {"-r", "--repo"}, description = "Specifies the URL of the Git repository")
@CommandLine.Option(names = {"-r", "--repo"}, defaultValue = "${YUPD_REPO}", description = "Specifies the URL of the Git repository (env: YUPD_REPO)")
String url;

@CommandLine.Option(names = {"--repo-type"}, required = true, description = "Specifies the repository type; valid values: 'gitlab' or 'github'")
@CommandLine.Option(names = {"--repo-type"}, required = true, defaultValue = "${YUPD_REPO_TYPE}", description = "Specifies the repository type; valid values: 'gitlab' or 'github' (env: YUPD_REPO_TYPE)")
GitRepository.Type repoType;

@CommandLine.Option(names = {"--project"}, required = true, description = "Identifies the project (e.g., 'srozange/yupd' for GitHub or '48539100' for GitLab)")
@CommandLine.Option(names = {"--project"}, required = true, defaultValue = "${YUPD_PROJECT}", description = "Identifies the project (e.g., 'srozange/yupd' for GitHub or '48539100' for GitLab) (env: YUPD_PROJECT)")
String project;

@CommandLine.Option(names = {"-b", "--branch"}, required = true, description = "Specifies the branch name of the target file to update")
@CommandLine.Option(names = {"-b", "--branch"}, required = true, defaultValue = "${YUPD_BRANCH}", description = "Specifies the branch name of the target file to update (env: YUPD_BRANCH)")
String branch;

@CommandLine.Option(names = {"-t", "--token"}, required = true, description = "Provides the authentication token")
@CommandLine.Option(names = {"-t", "--token"}, required = true, defaultValue = "${YUPD_TOKEN}", description = "Provides the authentication token (env: YUPD_TOKEN)")
String token;

@CommandLine.Option(names = {"-p", "--path"}, required = true, description = "Specifies the path of the target file to update")
@CommandLine.Option(names = {"-p", "--path"}, required = true, defaultValue = "${YUPD_PATH}", description = "Specifies the path of the target file to update (env: YUPD_PATH)")
String path;

@CommandLine.Option(names = {"-f", "--template"}, description = "Points to a local YAML file to be used as the source, instead of the remote one")
@CommandLine.Option(names = {"-f", "--template"}, defaultValue = "${YUPD_TEMPLATE}", description = "Points to a local YAML file to be used as the source, instead of the remote one (env: YUPD_TEMPLATE)")
Path sourceFile;

@CommandLine.Option(names = {"-m", "--commit-msg"}, description = "Provides a custom commit message for the update")
@CommandLine.Option(names = {"-m", "--commit-msg"}, defaultValue = "${YUPD_COMMIT_MSG}", description = "Provides a custom commit message for the update (env: YUPD_COMMIT_MSG)")
String commitMessage;

@CommandLine.Option(names = {"--set"}, required = true, description = "Allows setting YAML path expressions (e.g., metadata.name=new_name)")
@CommandLine.Option(names = {"--set"}, required = true, defaultValue = "${YUPD_SET}", description = "Allows setting YAML path expressions (e.g., metadata.name=new_name) (env: YUPD_SET)")
Map<String, String> yamlPathMap = new LinkedHashMap<>();

@CommandLine.Option(names = {"--merge-request", "--pull-request"}, defaultValue = "false", description = "If set to true, open either a pull request or a merge request based on the Git provider context")
@CommandLine.Option(names = {"--merge-request", "--pull-request"}, defaultValue = "${YUPD_MERGE_REQUEST:-false}", description = "If set to true, open either a pull request or a merge request based on the Git provider context (env: YUPD_MERGE_REQUEST)")
boolean mergeRequest;

@CommandLine.Option(names = {"--dry-run"}, defaultValue = "false", description = "If set to true, no write operation is done")
@CommandLine.Option(names = {"--dry-run"}, defaultValue = "${YUPD_DRY_RUN:-false}", description = "If set to true, no write operation is done (env: YUPD_DRY_RUN)")
boolean dryRun;

@CommandLine.Option(names = {"--verbose"}, defaultValue = "false", description = "If set to true, sets the log level to debug")
@CommandLine.Option(names = {"--verbose"}, defaultValue = "${YUPD_VERBOSE:-false}", description = "If set to true, sets the log level to debug (env: YUPD_VERBOSE)")
boolean verbose;

public YupdCommand(YamlRepoUpdater yamlRepoUpdater) {
Expand Down

0 comments on commit 890c3ac

Please sign in to comment.