|
| 1 | +<!-- meta --> |
| 2 | +<title> |
| 3 | + commitlog | manual |
| 4 | +</title> |
| 5 | +<meta name="description" content="commits to changelog generator"> |
| 6 | +<!-- meta end --> |
| 7 | + |
| 8 | +### [commitlog](/) |
| 9 | + |
| 10 | +[Home](/) [Manual](/manual) [Download ↓](/download) [API](/api) |
| 11 | + |
| 12 | +# API |
| 13 | + |
| 14 | +### General Guide |
| 15 | + |
| 16 | +commitlog also comes as a pkg that you could reuse to modify the behaviour of |
| 17 | +the commands and this is very limited at the moment since I'm still working on |
| 18 | +the best way to get plugins to work with the original CLI instead of having to |
| 19 | +write your own version of commitlog. |
| 20 | + |
| 21 | +The pkg contains the 2 base command's creators and behaviour modifiers, or more |
| 22 | +commonly known as the golang options pattern. |
| 23 | + |
| 24 | +Briefly put, You have one function that takes in unlimited amount of functions |
| 25 | +as parameter with each of these parameter functions being able to modify the |
| 26 | +behaviour of the returned instance. |
| 27 | + |
| 28 | +Easy way to explain this is with an example of the `releaser` API |
| 29 | + |
| 30 | +```go |
| 31 | +package main |
| 32 | + |
| 33 | +import ( |
| 34 | + "log" |
| 35 | + |
| 36 | + "github.com/barelyhuman/commitlog/pkg" |
| 37 | +) |
| 38 | + |
| 39 | +func main() { |
| 40 | + versionString := "v0.0.1" |
| 41 | + releaser, _ := pkg.CreateNewReleaser( |
| 42 | + versionString, |
| 43 | + pkg.WithMajorIncrement(), |
| 44 | + ) |
| 45 | + |
| 46 | + log.Println(releaser.String()) |
| 47 | + |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +here the `pkg.CreateNewReleaser` takes in one mandatory value which is the |
| 52 | +`versionString` and the 2nd parameter is optional here. |
| 53 | + |
| 54 | +Though, since we wish for the releaser to have a custom behaviour everytime the |
| 55 | +flags change, instead of writing entire functionalities inside various releaser |
| 56 | +functions, which would look like so |
| 57 | + |
| 58 | +```go |
| 59 | +releaser.IncrementMajor() |
| 60 | +releaser.IncrementMinor() |
| 61 | +``` |
| 62 | + |
| 63 | +I'd be unable to expose the builders / option functions out to the public for |
| 64 | +them to write custom behaviours that work directly with the `struct` being used |
| 65 | +by commitlog itself and instead you'd be writing wrappers around existing |
| 66 | +functions. Thus, adding another layer of abstraction which isn't needed for |
| 67 | +something that wants to be extended. |
| 68 | + |
| 69 | +This approach gives me the ability to expose a selected few properties for you |
| 70 | +to modify while writing your own builder/option function. |
| 71 | + |
| 72 | +The only pointer functions that releaser has is the one's that'll help with |
| 73 | +printing or identifying the final version's state. |
| 74 | + |
| 75 | +Since, you now know how the API is written, the go doc for this module should be |
| 76 | +able to help you with the remaining. |
| 77 | + |
| 78 | +[godoc↗](https://pkg.go.dev/github.com/barelyhuman/commitlog) |
| 79 | + |
| 80 | +> **Note**: if the go doc still hasn't been generated for v2.0.0, please go |
| 81 | +> through the source code to help you with the implementation details |
0 commit comments