Skip to content

Commit

Permalink
docs: Adds documentation and README
Browse files Browse the repository at this point in the history
  • Loading branch information
nszilard committed Jan 14, 2022
1 parent b52108b commit f43225d
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ dev: fmt check ## Builds a local dev version
package: bootstrap check ## Builds a production version
@env GOOS=linux GOARCH=amd64 go build -o .target/linux_amd64/${BINARY}

.PHONY: bootstrap fmt check test coverage show-coverage dev package clean help
docs: dev ## Generates markdown documentation
@.target/local/${BINARY} docs

.PHONY: bootstrap fmt check test coverage show-coverage dev package docs clean help

clean: ## Cleans up temporary and compiled files
@echo "==> Cleaning up ..."
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Slack

[![CI](https://github.com/nszilard/slack/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/nszilard/slack/actions/workflows/ci.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/nszilard/slack)](https://goreportcard.com/report/github.com/nszilard/slack)
[![GoDoc](https://godoc.org/github.com/nszilard/slack?status.svg)](https://godoc.org/github.com/nszilard/slack)

---

## About

`slack` is a simple CLI utility to send Slack messages based on a pre-defined templates, but it can also be used as a library.
Inspired by the [slack-go/slack](https://github.com/slack-go/slack) project, but wanted something simpler for personal use.

## Installation

``` shell
go get -u github.com/nszilard/slack
```

## Usage

It supports both environment variables as well as flags to set values, where the latter one takes priority if the values differ.

### Main command

| Environment variable | Flag | Description |
| :---------------------|:--------------------- |:----------------------------------------------------------------------------------------------|
| `SLACK_ORG_ID` | `slack-org-id` | Slack Organization ID. From the webhhok token **`Txxxxxx`**`/Bxxxxxx/xxxxxxx` the first group |
| `SLACK_WEBHOOK_ID` | `slack-webhook-id` | Slack Webhhok ID. From the webhhok token `Txxxxxx/`**`Bxxxxxx`**/`xxxxxxx` the second group |
| `SLACK_WEBHOOK_TOKEN` | `slack-webhook-token` | Slack Webhhok token. From the webhhok token `Txxxxxx/Bxxxxxx/`**`xxxxxxx`** the third group |
| `SLACK_CHANNEL` | `slack-channel` | Slack channel name (or personal ID) to send the message to |
| `SLACK_USER` | `slack-user` | To specify the username for the published message. |
| `SLACK_USER_IMAGE` | `slack-user-image` | To specify a URL to an image to use as the profile photo alongside the message |

### Changelog command

| Environment variable | Flag | Description |
| :---------------------|:------------------- |:--------------------------------------------------------|
| `CHANGELOG_SERVICE` | `changelog-service` | Name of the Git repositry or preferred service name |
| `CHANGELOG_VERSION` | `changelog-version` | The new version |
| `CHANGELOG_COMMITS` | | Commits which have been released with the given version |

### See generated docs

* [slack](docs/slack.md) - CLI to send Slack messages programmatically.
36 changes: 36 additions & 0 deletions cmd/cmdDocs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

var docsLocation string

//----------------------------------------
// Cobra command
//----------------------------------------
var documentationCmd = &cobra.Command{
Use: "docs",
Aliases: []string{"doc", "documentation"},
Short: "Generates markdown documentation",

Hidden: true,

Args: cobra.NoArgs,
RunE: generateMarkdown,
}

func generateMarkdown(cmd *cobra.Command, args []string) error {
return doc.GenMarkdownTree(cmd.Root(), docsLocation)
}

//----------------------------------------
// Cobra command init
//----------------------------------------
func init() {
// Adding documentation command to the root command
mainCmd.AddCommand(documentationCmd)

docsLocation = "docs"
}
22 changes: 22 additions & 0 deletions cmd/cmdDocs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"os"
"testing"

"github.com/spf13/cobra"
)

func Test_generateMarkdown(t *testing.T) {
folder := "temp"
err := os.Mkdir(folder, 0755)
if err != nil {
t.Fatalf("failed to create temp folder")
}
docsLocation = folder
defer os.RemoveAll(folder)

if err := generateMarkdown(&cobra.Command{Use: "test"}, nil); err != nil {
t.Errorf("docs: unexpected error: %v", err)
}
}
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func Execute() error {
// Cobra command init
//----------------------------------------
func init() {
// Hide the completion command
mainCmd.CompletionOptions.HiddenDefaultCmd = true

// Global persistent flags that are required to have a value
mainCmd.PersistentFlags().StringVarP(&slackOrgID, models.ArgSlackOrgIDFlag, "O", "", "Slack Organization ID in the form of: Txxxxxx. (Required)")
mainCmd.PersistentFlags().StringVarP(&slackAppID, models.ArgSlackWebhookIDFlag, "W", "", "Slack Webhook ID in the form of: Bxxxxxx. (Required)")
Expand Down
26 changes: 26 additions & 0 deletions docs/slack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## slack

CLI to send Slack messages programmatically.

### Synopsis

A simple CLI tool to send Slack messages programmatically using pre-defined templates.

### Options

```
-d, --debug Enables Debug logging.
-h, --help help for slack
-C, --slack-channel string Slack Channel where to send the message. (Optional)
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required)
-U, --slack-user string Name to use when sending the message. (Optional)
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional)
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required)
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required)
```

### SEE ALSO

* [slack changelog](slack_changelog.md) - Sends a message using the Changelog template.
* [slack simple](slack_simple.md) - Sends a simple text message.

36 changes: 36 additions & 0 deletions docs/slack_changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## slack changelog

Sends a message using the Changelog template.

### Synopsis

Sends a changelog message using the provided values.

```
slack changelog [flags]
```

### Options

```
-s, --changelog-service string Service name as it is registered in Git. (Required)
-v, --changelog-version string The new tag. (Required)
-h, --help help for changelog
```

### Options inherited from parent commands

```
-d, --debug Enables Debug logging.
-C, --slack-channel string Slack Channel where to send the message. (Optional)
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required)
-U, --slack-user string Name to use when sending the message. (Optional)
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional)
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required)
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required)
```

### SEE ALSO

* [slack](slack.md) - CLI to send Slack messages programmatically.

34 changes: 34 additions & 0 deletions docs/slack_simple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## slack simple

Sends a simple text message.

### Synopsis

Sends a simple text message.

```
slack simple [flags]
```

### Options

```
-h, --help help for simple
```

### Options inherited from parent commands

```
-d, --debug Enables Debug logging.
-C, --slack-channel string Slack Channel where to send the message. (Optional)
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required)
-U, --slack-user string Name to use when sending the message. (Optional)
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional)
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required)
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required)
```

### SEE ALSO

* [slack](slack.md) - CLI to send Slack messages programmatically.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ require (
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -237,8 +238,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand Down Expand Up @@ -294,6 +297,7 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig=
Expand Down Expand Up @@ -736,6 +740,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand All @@ -745,6 +750,7 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down

0 comments on commit f43225d

Please sign in to comment.