Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,26 @@ builds:
- windows
goarch:
- amd64



- id: build-cli
main: ./cmd/answer-cli/.
binary: answer-cli
ldflags: -s -w -X main.version={{.RawVersion}} -X main.revision={{.ShortCommit}} -X main.buildTime={{.Date}}
flags: -v
goos:
- linux
- darwin
goarch:
- amd64
- arm64
- id: build-cli-windows
main: ./cmd/answer-cli/.
binary: answer-cli
ldflags: -s -w -X main.version={{.RawVersion}} -X main.revision={{.ShortCommit}} -X main.buildTime={{.Date}}
flags: -v
goos:
- windows
goarch:
- amd64

archives:
- name_template: >-
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.PHONY: build clean ui
.PHONY: build build-cli clean ui

VERSION=2.0.2
BIN=answer
DIR_SRC=./cmd/answer
CLI_BIN=answer-cli
CLI_DIR_SRC=./cmd/answer-cli
DOCKER_CMD=docker

GO_ENV=CGO_ENABLED=0 GO111MODULE=on
Revision=$(shell git rev-parse --short HEAD 2>/dev/null || echo "")
GO_FLAGS=-ldflags="-X github.com/apache/answer/cmd.Version=$(VERSION) -X 'github.com/apache/answer/cmd.Revision=$(Revision)' -X 'github.com/apache/answer/cmd.Time=`date +%s`' -extldflags -static"
CLI_GO_FLAGS=-ldflags="-X main.version=$(VERSION) -X main.revision=$(Revision) -X main.buildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)"
GO=$(GO_ENV) "$(shell which go)"

GOLANGCI_VERSION ?= v2.6.2
Expand All @@ -22,6 +25,9 @@ $(GOLANGCI):
build: generate
@$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)

build-cli:
@$(GO) build $(CLI_GO_FLAGS) -o $(CLI_BIN) $(CLI_DIR_SRC)

# https://dev.to/thewraven/universal-macos-binaries-with-go-1-16-3mm3
universal: generate
@GOOS=darwin GOARCH=amd64 $(GO_ENV) $(GO) build $(GO_FLAGS) -o ${BIN}_amd64 $(DIR_SRC)
Expand All @@ -31,10 +37,10 @@ universal: generate

generate:
@$(GO) get github.com/swaggo/swag/cmd/swag@v1.16.3
@$(GO) get github.com/google/wire/cmd/wire@v0.5.0
@$(GO) get github.com/google/wire/cmd/wire@v0.7.0
@$(GO) get go.uber.org/mock/mockgen@v0.6.0
@$(GO) install github.com/swaggo/swag/cmd/swag@v1.16.3
@$(GO) install github.com/google/wire/cmd/wire@v0.5.0
@$(GO) install github.com/google/wire/cmd/wire@v0.7.0
@$(GO) install go.uber.org/mock/mockgen@v0.6.0
@$(GO) generate ./...
@$(GO) mod tidy
Expand All @@ -50,7 +56,7 @@ test:
# clean all build result
clean:
@$(GO) clean ./...
@rm -f $(BIN)
@rm -f $(BIN) $(CLI_BIN)

install-ui-packages:
@corepack enable
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ We value your feedback and suggestions to improve our documentation. If you have

You can also check out the [plugins here](https://answer.apache.org/plugins).

### Agent access

An administrator can enable **Personal access tokens** under **Admin → Security**. Users can then create scoped, expiring tokens from **Settings → Personal access tokens** for use with `answer-cli` or another HTTP client.

Install the CLI from source:

```bash
go install github.com/apache/answer/cmd/answer-cli@latest
answer-cli auth login --server https://answer.example.com --with-token
```

Install the portable Answer Agent Skill for supported coding agents:

```bash
npx skills add apache/answer
```

The Skill uses `answer-cli` to search Answer and, with explicit user approval, create questions, post answers, and vote.

## Building from Source

### Prerequisites
Expand All @@ -55,6 +74,8 @@ $ make generate
$ make ui
# Install backend dependencies and build
$ make build
# Build the remote API client
$ make build-cli
```

## Contributing
Expand Down
68 changes: 68 additions & 0 deletions cmd/answer-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package main

import (
"os"
"runtime/debug"

"github.com/apache/answer/internal/answercli"
)

var (
version = "dev"
revision string
buildTime string
)

func main() {
resolvedRevision, resolvedBuildTime, modified := buildMetadata()
command := answercli.NewRootCommand(answercli.Options{
Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr,
Version: version, Revision: resolvedRevision, BuildTime: resolvedBuildTime, Modified: modified,
})
if err := command.Execute(); err != nil {
os.Exit(answercli.ExitCode(err))
}
}

func buildMetadata() (resolvedRevision, resolvedBuildTime string, modified bool) {
resolvedRevision = revision
resolvedBuildTime = buildTime
info, ok := debug.ReadBuildInfo()
if !ok {
return resolvedRevision, resolvedBuildTime, false
}
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
if resolvedRevision == "" {
resolvedRevision = setting.Value
}
case "vcs.time":
if resolvedBuildTime == "" {
resolvedBuildTime = setting.Value
}
case "vcs.modified":
modified = setting.Value == "true"
}
}
return resolvedRevision, resolvedBuildTime, modified
}
16 changes: 11 additions & 5 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading