Skip to content

Commit 61eb4d1

Browse files
committed
Revert "Merge pull request #1 from daptin/claude/daptin-cli-creation-mVurH"
This reverts commit b9b1a60, reversing changes made to a6b22ab.
1 parent b9b1a60 commit 61eb4d1

26 files changed

Lines changed: 1020 additions & 4269 deletions

.gitignore

Lines changed: 0 additions & 24 deletions
This file was deleted.

Makefile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
GOCMD=go
2+
GOTEST=$(GOCMD) test
3+
GOVET=$(GOCMD) vet
4+
BINARY_NAME=daptin-cli
5+
VERSION?=0.0.0
6+
SERVICE_PORT?=3000
7+
DOCKER_REGISTRY?= #if set it should finished by /
8+
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true
9+
10+
GREEN := $(shell tput -Txterm setaf 2)
11+
YELLOW := $(shell tput -Txterm setaf 3)
12+
WHITE := $(shell tput -Txterm setaf 7)
13+
CYAN := $(shell tput -Txterm setaf 6)
14+
RESET := $(shell tput -Txterm sgr0)
15+
16+
.PHONY: all test build vendor
17+
18+
all: help
19+
20+
## Build:
21+
build: ## Build your project and put the output binary in out/bin/
22+
mkdir -p out/bin
23+
GO111MODULE=on $(GOCMD) build -mod vendor -o out/bin/$(BINARY_NAME) .
24+
25+
clean: ## Remove build related file
26+
rm -fr ./bin
27+
rm -fr ./out
28+
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
29+
30+
vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
31+
$(GOCMD) mod vendor
32+
33+
watch: ## Run the code with cosmtrek/air to have automatic reload on changes
34+
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
35+
docker run -it --rm -w /go/src/$(PACKAGE_NAME) -v $(shell pwd):/go/src/$(PACKAGE_NAME) -p $(SERVICE_PORT):$(SERVICE_PORT) cosmtrek/air
36+
37+
## Test:
38+
test: ## Run the tests of the project
39+
ifeq ($(EXPORT_RESULT), true)
40+
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
41+
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
42+
endif
43+
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
44+
45+
coverage: ## Run the tests of the project and export the coverage
46+
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
47+
$(GOCMD) tool cover -func profile.cov
48+
ifeq ($(EXPORT_RESULT), true)
49+
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
50+
GO111MODULE=off go get -u github.com/axw/gocov/gocov
51+
gocov convert profile.cov | gocov-xml > coverage.xml
52+
endif
53+
54+
## Lint:
55+
lint: lint-go lint-dockerfile lint-yaml ## Run all available linters
56+
57+
lint-dockerfile: ## Lint your Dockerfile
58+
# If dockerfile is present we lint it.
59+
ifeq ($(shell test -e ./Dockerfile && echo -n yes),yes)
60+
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
61+
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--format checkstyle" || echo "" ))
62+
$(eval OUTPUT_FILE = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "| tee /dev/tty > checkstyle-report.xml" || echo "" ))
63+
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint $(OUTPUT_OPTIONS) - < ./Dockerfile $(OUTPUT_FILE)
64+
endif
65+
66+
lint-go: ## Use golintci-lint on your project
67+
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
68+
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)
69+
70+
lint-yaml: ## Use yamllint on the yaml file of your projects
71+
ifeq ($(EXPORT_RESULT), true)
72+
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
73+
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
74+
endif
75+
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
76+
77+
## Docker:
78+
docker-build: ## Use the dockerfile to build the container
79+
docker build --rm --tag $(BINARY_NAME) .
80+
81+
docker-release: ## Release the container with tag latest and version
82+
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):latest
83+
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
84+
# Push the docker images
85+
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):latest
86+
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
87+
88+
## Help:
89+
help: ## Show this help.
90+
@echo ''
91+
@echo 'Usage:'
92+
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
93+
@echo ''
94+
@echo 'Targets:'
95+
@awk 'BEGIN {FS = ":.*?## "} { \
96+
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
97+
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
98+
}' $(MAKEFILE_LIST)

README.md

Lines changed: 12 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,213 +1,33 @@
11
# Daptin CLI
22

3-
Command-line interface for [Daptin](https://github.com/daptin/daptin) Backend-as-a-Service.
4-
5-
Built with TypeScript, inspired by [daptin-js-client](https://github.com/artpar/daptin-js-client).
6-
7-
## Installation
8-
9-
```bash
10-
npm install -g daptin-cli
11-
```
12-
13-
Or build from source:
14-
15-
```bash
16-
git clone https://github.com/daptin/daptin-cli.git
17-
cd daptin-cli
18-
npm install
19-
npm run build
20-
npm link
21-
```
22-
23-
## Quick Start
24-
25-
```bash
26-
# Add a Daptin server
27-
daptin-cli config add local http://localhost:6336
28-
29-
# Sign in
30-
daptin-cli signin admin@example.com
31-
32-
# List all tables
33-
daptin-cli tables
34-
35-
# List records from a table
36-
daptin-cli list user_account --page-size 20
37-
38-
# Get a single record
39-
daptin-cli get user_account <reference_id>
40-
```
41-
42-
## Configuration
43-
44-
The CLI stores configuration in `~/.daptin/config.yaml`. You can manage multiple server contexts:
45-
46-
```bash
47-
# Add servers
48-
daptin-cli config add local http://localhost:6336
49-
daptin-cli config add production https://api.example.com
50-
51-
# Switch active server
52-
daptin-cli config use production
53-
54-
# List all servers
55-
daptin-cli config list
56-
57-
# Show current context
58-
daptin-cli config show
59-
60-
# Remove a server
61-
daptin-cli config remove local
62-
```
63-
64-
Override the endpoint on any command with `--endpoint`:
65-
66-
```bash
67-
daptin-cli --endpoint http://localhost:6336 tables
68-
```
69-
70-
## Global Options
71-
72-
| Flag | Description | Default |
73-
|------|-------------|---------|
74-
| `-e, --endpoint <url>` | Daptin server endpoint | from config |
75-
| `-c, --config <path>` | Config file path | `~/.daptin/config.yaml` |
76-
| `-o, --output <format>` | Output format (`table`, `json`) | `table` |
77-
| `-t, --token <token>` | Auth token | from config |
78-
| `--debug` | Enable debug output | `false` |
79-
80-
## Commands
81-
82-
### Authentication
3+
CLI for talking to [Daptin server](https://github.com/daptin/daptin)
834

845
```bash
85-
# Create a new account
86-
daptin-cli signup user@example.com
87-
88-
# Sign in (prompts for password)
89-
daptin-cli signin user@example.com
90-
91-
# Sign in with 2FA
92-
daptin-cli signin-2fa user@example.com
93-
94-
# Show current user info
95-
daptin-cli whoami
96-
```
97-
98-
### Schema Discovery
99-
100-
```bash
101-
# List all tables
102-
daptin-cli tables
103-
daptin-cli tables --columns table_name,is_top_level,default_permission
104-
105-
# Describe a table (columns, relations, actions)
106-
daptin-cli describe user_account
107-
daptin-cli describe product --columns ColumnName,ColumnType,DataType,IsNullable
108-
```
109-
110-
### CRUD Operations
111-
112-
```bash
113-
# List records
114-
daptin-cli list product
115-
daptin-cli list product --page-size 50 --page 2
116-
daptin-cli list product --columns name,price,reference_id
117-
daptin-cli list product --sort -price,name
118-
daptin-cli list product --include category_id
119-
120-
# Get a single record
121-
daptin-cli get product <reference_id>
122-
daptin-cli get product <reference_id> --columns name,price
123-
124-
# Create a record
125-
daptin-cli create product --data '{"name": "Widget", "price": 9.99}'
126-
127-
# Update a record
128-
daptin-cli update product <reference_id> --data '{"price": 12.99}'
129-
130-
# Delete a record
131-
daptin-cli delete product <reference_id>
132-
133-
# Query relationships
134-
daptin-cli relation customer <reference_id> order_id --page-size 20
6+
go get github.com/daptin/daptin-cli
7+
go install github.com/daptin/daptin-cli
8+
go build -o daptin-cli
1359
```
13610

137-
### Actions
13811

12+
Describe a table schema
13913
```bash
140-
# List all actions
141-
daptin-cli actions
142-
143-
# List actions for a specific table
144-
daptin-cli actions user_account
145-
146-
# Show action schema (input/output fields)
147-
daptin-cli action-describe user_account signin
148-
149-
# Execute an action
150-
daptin-cli execute user_account generate_jwt_token --data '{"email": "user@example.com"}'
151-
152-
# Execute an instance-level action
153-
daptin-cli execute order mark_shipped --id <order_reference_id> --data '{"tracking_number": "ABC123"}'
14+
./daptin-cli --output table describe table world
15415
```
15516

156-
### Aggregation
17+
List items of a table
15718

158-
```bash
159-
# Count records
160-
daptin-cli aggregate product --columns count
161-
162-
# Sum and average
163-
daptin-cli aggregate product --columns "count,sum(price),avg(price)"
164-
165-
# Group by
166-
daptin-cli aggregate order --columns "status,count,sum(total)" --group status
167-
168-
# With filters
169-
daptin-cli aggregate product --columns "count,avg(price)" --filter "gt(price,100)"
170-
171-
# With limit and sort
172-
daptin-cli aggregate order --columns "status,count" --group status --sort "-count" --limit 10
173-
```
174-
175-
### Output Formats
19+
./daptin-cli list --pageSize 50 --columns <col1>,<col2> <tableName>
17620

17721
```bash
178-
# Table output (default)
179-
daptin-cli list product --output table
180-
181-
# JSON output
182-
daptin-cli list product --output json
183-
184-
# JSON output piped to jq
185-
daptin-cli list product -o json | jq '.[].name'
22+
./daptin-cli list --pageSize 50 --columns reference_id,table_name world
18623
```
18724

188-
## Environment Variables
18925

190-
| Variable | Description |
191-
|----------|-------------|
192-
| `DAPTIN_CLI_CONFIG` | Path to config file |
193-
| `DAPTIN_ENDPOINT` | Default server endpoint |
26+
Get one row by reference_id
19427

195-
## Development
28+
./daptin-cli get-by-id --columns reference_id,table_name <table_name> <reference_id>
19629

19730
```bash
198-
# Install dependencies
199-
npm install
200-
201-
# Run in development mode
202-
npx tsx src/index.ts tables
203-
204-
# Type check
205-
npm run typecheck
206-
207-
# Build
208-
npm run build
31+
./daptin-cli get-by-id --columns reference_id,table_name,is_top_level world 019228bb-a7cd-773b-a465-c92d7c54d956
20932
```
21033

211-
## License
212-
213-
MIT

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.1

config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Hosts:
2+
- Name: local
3+
Endpoint: http://localhost:6336
4+
- Name: dapt.in
5+
Endpoint: https://dashboard.dapt.in
6+
CurrentContext:
7+
AuthToken

generate_client_openapi.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest
2+
3+
curl http://localhost:6336/openapi.yaml > daptin-openapi.yaml
4+
5+
oapi-codegen --config=cfg.yaml client/daptin-openapi.yaml

0 commit comments

Comments
 (0)