Skip to content

Commit

Permalink
Extract komplete into its own repository
Browse files Browse the repository at this point in the history
This library was developed in
[git-spice](https://github.com/abhinav/git-spice),
specifically with plans to extract and open source separately
under a different license.
  • Loading branch information
abhinav committed Oct 5, 2024
1 parent f2bdb03 commit e1a6d40
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changes/header.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).
Empty file added .changes/unreleased/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions .changie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
changesDir: .changes
unreleasedDir: unreleased
headerPath: header.tpl.md
changelogPath: CHANGELOG.md
versionExt: md
versionFormat: '## {{.Version}} - {{.Time.Format "2006-01-02"}}'
kindFormat: '### {{.Kind}}'
changeFormat: '- {{.Body}}'
kinds:
- label: Added
auto: minor
- label: Changed
auto: major
- label: Deprecated
auto: minor
- label: Removed
auto: major
- label: Fixed
auto: patch
- label: Security
auto: patch
newlines:
afterChangelogHeader: 0
beforeChangelogVersion: 1
endOfVersion: 1
envPrefix: CHANGIE_
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ '*' ]

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Check out repository
- uses: actions/setup-go@v5
name: Set up Go
with:
go-version: stable
cache: false
- uses: golangci/golangci-lint-action@v6
name: Install golangci-lint
with:
version: latest
args: --help
- run: make lint
name: Lint

build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.22.x", "1.23.x"]

steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true
- name: Test
run: make cover
- name: Upload coverage
uses: codecov/codecov-action@v4
66 changes: 66 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Publish documentation

on:
# Publish documentation when a new release is tagged.
push:
tags: ['v*']

# Allow manually publishing documentation from a specific hash.
workflow_dispatch:
inputs:
head:
description: "Git commit to publish documentation for."
required: true
type: string

# If two concurrent runs are started,
# prefer the latest one.
concurrency:
group: "pages"
cancel-in-progress: true

jobs:

build:
name: Build website
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Check out head specified by workflow_dispatch,
# or the tag if this fired from the push event.
ref: ${{ inputs.head || github.ref }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable
cache: true
- name: Install doc2go
run: go install go.abhg.dev/doc2go@latest
- name: Generate API reference
run: doc2go -home go.abhg.dev/komplete ./...
- name: Upload pages
uses: actions/upload-pages-artifact@v3

publish:
name: Publish website
# Don't run until the build has finished running.
needs: build

# Grants the GITHUB_TOKEN used by this job
# permissions needed to publish the website.
permissions:
pages: write
id-token: write

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


No releases yet, this file will be updated when generating your first release.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SHELL = /bin/bash

PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Setting GOBIN and PATH ensures two things:
# - All 'go install' commands we run
# only affect the current directory.
# - All installed tools are available on PATH
# for commands like go generate.
export GOBIN = $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)

TEST_FLAGS ?= -race

.PHONY: all
all: build lint test

.PHONY: build
build:
go build ./...

.PHONY: lint
lint: golangci-lint tidy-lint

.PHONY: test
test:
go test $(TEST_FLAGS) ./...

.PHONY: cover
cover:
go test $(TEST_FLAGS) -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out -o cover.html

.PHONY: tidy-lint
tidy-lint:
go mod tidy -diff

.PHONY: golangci-lint
golangci-lint:
golangci-lint run

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
This directory provides komplete, a command-line completion engine for Kong.
The source code in this directory is made available under the BSD3 license.
[![Go Reference](https://pkg.go.dev/badge/go.abhg.dev/komplete.svg)](https://pkg.go.dev/go.abhg.dev/komplete)
[![CI](https://github.com/abhinav/komplete/actions/workflows/ci.yml/badge.svg)](https://github.com/abhinav/komplete/actions/workflows/ci.yml)

komplete is a command-line completion engine for the
[Kong CLI parser](https://github.com/alecthomas/kong)
See [API Reference](https://abhinav.github.io/komplete/) for usage information.

This software is made available under the BSD-3 license.
See LICENSE for the full license text.
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module go.abhg.dev/komplete

go 1.22

require (
github.com/alecthomas/kong v1.2.1
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY=
github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v1.2.1 h1:E8jH4Tsgv6wCRX2nGrdPyHDUCSG83WH2qE4XLACD33Q=
github.com/alecthomas/kong v1.2.1/go.mod h1:rKTSFhbdp3Ryefn8x5MOEprnRFQ7nlmMC01GKhehhBM=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10 h1:XwHQ5xDtYPdtBbVPyRO6UZoWZe8/mbKUb076f8x7RvI=
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10/go.mod h1:gv0DYOzHEsKgo31lTCDGauIg4DTTGn41Bzp+t3wSOlk=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 1 addition & 4 deletions komplete.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// SPDX-License-Identifier: BSD-3-Clause

// Package komplete is a package for generating completions for Kong CLIs.
//
// To use it, build a Kong parser from your CLI grammar,
Expand Down Expand Up @@ -44,7 +42,6 @@ import (

"github.com/alecthomas/kong"
"github.com/buildkite/shellwords"
"go.abhg.dev/gs/internal/must"
)

// Implementation notes:
Expand Down Expand Up @@ -395,7 +392,7 @@ parser:
return nil

default:
must.Failf("unexpected flag status: %v", status)
panic(fmt.Sprintf("unexpected flag status: %v", status))
}

case kong.FlagValueToken:
Expand Down
21 changes: 14 additions & 7 deletions komplete_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// SPDX-License-Identifier: BSD-3-Clause

package komplete

import (
Expand All @@ -11,19 +9,23 @@ import (
"github.com/alecthomas/kong"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/gs/internal/ioutil"
)

func TestCommandRun(t *testing.T) {
shells := []string{"bash", "zsh", "fish"}
for _, shell := range shells {
t.Run(shell, func(t *testing.T) {
var stdout bytes.Buffer
var stdout, stderr bytes.Buffer
defer func() {
if stderr.Len() > 0 {
t.Logf("stderr: %s", stderr.String())
}
}()

parser, err := kong.New(
&struct{}{},
kong.Name("test"),
kong.Writers(&stdout, ioutil.TestOutputWriter(t, "")),
kong.Writers(&stdout, &stderr),
)
require.NoError(t, err)

Expand All @@ -34,12 +36,17 @@ func TestCommandRun(t *testing.T) {
}

t.Run("unknown", func(t *testing.T) {
var stdout bytes.Buffer
var stdout, stderr bytes.Buffer
defer func() {
if stderr.Len() > 0 {
t.Logf("stderr: %s", stderr.String())
}
}()

parser, err := kong.New(
&struct{}{},
kong.Name("test"),
kong.Writers(&stdout, ioutil.TestOutputWriter(t, "")),
kong.Writers(&stdout, &stderr),
)
require.NoError(t, err)

Expand Down
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>abhinav/renovate-config"
]
}

0 comments on commit e1a6d40

Please sign in to comment.