Skip to content

Commit

Permalink
refactor(docs): Improve examples in README and CLI (#64)
Browse files Browse the repository at this point in the history
* refactor(docs): Improve examples in README and CLI

* docs: fix typo (MAJOR != MAYOR)

* refactor: Update flag help text
  • Loading branch information
sergiotejon authored Nov 19, 2024
1 parent c22c801 commit 312dcda
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 69 deletions.
53 changes: 24 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,29 @@ Increment the version of the project according to the conventional commits speci
**Flags:**
- `-c`, `--changelog`: generate the changelog for the newest version

- `-i`, `--increment`: manually specify the desired increment {MAYOR, MINOR, PATCH}
- `-i`, `--increment`: manually specify the desired increment {MAJOR, MINOR, PATCH}



**Examples of usage:**

To bump the version of a project, run:
```bash
```shell
# To bump the version of a project, run:
gommitizen bump
```
This will bump the version of all projects in the current directory.
If you want to bump the version of a specific project, run:
```bash
# This will bump the version of all projects in the current directory.

# If you want to bump the version of a specific project, run:
gommitizen bump -d <directory>
```
This will bump the version of the project in the given directory.
If you want to bump the version of projects and generate a changelog, run:
```bash
# This will bump the version of the project in the given directory.

# If you want to bump the version of projects and generate a changelog, run:
gommitizen bump -c
```
This will bump the version of the projects and generate a changelog with the changes made since the last version.
If you want to bump the version of project to a major version, run:
```bash
gommitizen bump -i major
```
# This will bump the version of the projects and generate a changelog with the changes made since the last version.

# If you want to bump the version of project to a major version, run:
gommitizen bump -i MAJOR

```



Expand All @@ -99,19 +96,15 @@ information and all the information saved in the config file.

**Examples of usage:**

To show all information in yaml format, run:
```bash
```shell
# To show all information in yaml format, run:
gommitizen get all -o yaml
```
To show the version of the projects in plain format, run:
```bash
# To show the version of the projects in plain format, run:
gommitizen get version -o plain
```
or just:
```bash
# or just:
gommitizen get version
```

```



Expand All @@ -134,17 +127,19 @@ Initialize the repository to use gommitizen. It will create a file with the vers
the first commit of the project.

**Flags:**
- `-`, `--bump-changelog`: Update changelog on bump

- `-p`, `--prefix`: Select a prefix for the version file



**Examples of usage:**

To initialize the versioning of a project, run:
```bash
```shell
# To initialize the versioning of a project, run:
gommitizen init -d <directory> -p <prefix>`
# This will create a .version.json file in the given directory with the version 0.0.0.
```
This will create a .version.json file in the given directory with the version 0.0.0.



Expand Down
2 changes: 2 additions & 0 deletions README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Next a list of the available commands and their description:
{{ if .Example }}
**Examples of usage:**

```shell
{{ .Example }}
```
{{ end }}

{{ if .Commands }}
Expand Down
27 changes: 9 additions & 18 deletions internal/pkg/cmd/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@ func bumpCmd() *cobra.Command {
Use: "bump",
Short: "Make a version bump",
Long: `Increment the version of the project according to the conventional commits specification.`,
Example: "To bump the version of a project, run:\n" +
"```bash\n" +
Example: "# To bump the version of a project, run:\n" +
"gommitizen bump\n" +
"```\n" +
"This will bump the version of all projects in the current directory.\n" +
"If you want to bump the version of a specific project, run:\n" +
"```bash\n" +
"# This will bump the version of all projects in the current directory.\n\n" +
"# If you want to bump the version of a specific project, run:\n" +
"gommitizen bump -d <directory>\n" +
"```\n" +
"This will bump the version of the project in the given directory.\n" +
"If you want to bump the version of projects and generate a changelog, run:\n" +
"```bash\n" +
"# This will bump the version of the project in the given directory.\n\n" +
"# If you want to bump the version of projects and generate a changelog, run:\n" +
"gommitizen bump -c\n" +
"```\n" +
"This will bump the version of the projects and generate a changelog with the changes made since the last " +
"version.\n" +
"If you want to bump the version of project to a major version, run:\n" +
"```bash\n" +
"gommitizen bump -i major\n" +
"```\n",
"# This will bump the version of the projects and generate a changelog with the changes made since the last version.\n\n" +
"# If you want to bump the version of project to a major version, run:\n" +
"gommitizen bump -i MAJOR\n",
PreRunE: func(cmd *cobra.Command, args []string) error {
increment, _ := cmd.Flags().GetString("increment")
if increment == "" {
Expand All @@ -67,7 +58,7 @@ func bumpCmd() *cobra.Command {
}

cmd.Flags().BoolVarP(&createChangelog, "changelog", "c", false, "generate the changelog for the newest version")
cmd.Flags().StringVarP(&incrementType, "increment", "i", "", "manually specify the desired increment {MAYOR, MINOR, PATCH}")
cmd.Flags().StringVarP(&incrementType, "increment", "i", "", "manually specify the desired increment {MAJOR, MINOR, PATCH}")

return cmd
}
Expand Down
20 changes: 7 additions & 13 deletions internal/pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ func getCmd() *cobra.Command {
Short: "Give a list of projects, their versions and other information",
Long: `Show information about the projects in the repository. It can show the version, the alias, the commit
information and all the information saved in the config file.`,
Example: "To show all information in yaml format, run:\n" +
"```bash\n" +
Example: "# To show all information in yaml format, run:\n" +
"gommitizen get all -o yaml\n" +
"```\n" +
"To show the alias of the projects in plain format, run:\n" +
"```bash\n" +
"gommitizen get alias -o plain\n" +
"```\n" +
"or just:\n" +
"```bash\n" +
"gommitizen get version\n" +
"```\n",
"# To show the version of the projects in plain format, run:\n" +
"gommitizen get version -o plain\n" +
"# or just:\n" +
"gommitizen get version\n",
PreRunE: func(cmd *cobra.Command, args []string) error {
if output != "json" && output != "yaml" && output != "plain" {
return fmt.Errorf("invalid output format: %s, supported values: json, yaml, plain", output)
Expand All @@ -49,8 +43,8 @@ information and all the information saved in the config file.`,
},
}

cmd.PersistentFlags().StringVarP(&output, getOutputFlagName, "o", "plain", "Select the output format {json, yaml, plain}")
cmd.PersistentFlags().StringVarP(&alias, getAliasFlagName, "a", "", "A alias to look for a project to show information")
cmd.PersistentFlags().StringVarP(&output, getOutputFlagName, "o", "plain", "select the output format {json, yaml, plain}")
cmd.PersistentFlags().StringVarP(&alias, getAliasFlagName, "a", "", "a alias to look for a project to show information")

cmd.AddCommand(getAllCmd())
cmd.AddCommand(getVersionCmd())
Expand Down
12 changes: 5 additions & 7 deletions internal/pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ func initCmd() *cobra.Command {
Short: "Start a repository to use gommitizen",
Long: `Initialize the repository to use gommitizen. It will create a file with the version of the project and
the first commit of the project.`,
Example: "To initialize the versioning of a project, run: \n" +
"```bash\n" +
"gommitizen init -d <directory> -a <alias>`\n" +
"```\n" +
"This will create a .version.json file in the given directory with the version 0.0.0.",
Example: "# To initialize the versioning of a project, run: \n" +
"gommitizen init -d <directory> -p <prefix>`\n" +
"# This will create a .version.json file in the given directory with the version 0.0.0.",
Run: func(cmd *cobra.Command, args []string) {
dirPath := cmd.Root().Flag(rootDirPathFlagName).Value.String()
initRun(dirPath, alias, updateChangelogOnBump)
},
}

cmd.Flags().StringVarP(&alias, "alias", "a", "", "Set a alias for the version file")
cmd.Flags().BoolVar(&updateChangelogOnBump, initBumpFlagName, false, "Update changelog on bump")
cmd.Flags().StringVarP(&alias, "alias", "a", "", "set a alias for the version file")
cmd.Flags().BoolVar(&updateChangelogOnBump, initBumpFlagName, false, "update changelog on bump")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ each project.`,
},
}

root.PersistentFlags().StringVarP(&dirPath, "directory", "d", "", "Select a directory to run the command")
root.PersistentFlags().BoolVar(&debug, rootDebugFlagName, false, "Enable debug")
root.PersistentFlags().StringVarP(&dirPath, "directory", "d", "", "select a directory to run the command")
root.PersistentFlags().BoolVar(&debug, rootDebugFlagName, false, "enable debug")

root.AddCommand(initCmd())
root.AddCommand(bumpCmd())
Expand Down

0 comments on commit 312dcda

Please sign in to comment.