Skip to content

Commit

Permalink
Remove bindata and upgrade release tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Feb 5, 2021
1 parent d208df0 commit 09b4367
Show file tree
Hide file tree
Showing 13 changed files with 2,299 additions and 325 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
/.DS_Store
/curl2httpie
/curl2httpie-*.zip
/curl_src
72 changes: 42 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
deps :
cd ../ \
&& which go1.12.16 \
|| (go get golang.org/dl/go1.12.16 && go1.12.16 download)
which gopherjs || go get github.com/gopherjs/gopherjs

.PHONY: curl2httpie.js
curl2httpie.js : deps
GOPHERJS_GOROOT="/Users/bob/sdk/go1.12.16" gopherjs build -m -o web/curl2httpie.js ./cmd/curl2httpie.js

generateOptions :
go run cmd/generateOptions/main.go -path="$(path)"
go-bindata -ignore .gitignore -pkg curl -o ./curl/bindata.go data/

initGithooks:
git config core.hooksPath .githooks

NAME := curl2httpie
PACKAGE_NAME := github.com/dcb9/curl2httpie
VERSION := `git describe --dirty`
Expand All @@ -25,36 +8,65 @@ BUILD_DIR := build
VAR_SETTING := -X $(PACKAGE_NAME)/constant.Version=$(VERSION) -X $(PACKAGE_NAME)/constant.Commit=$(COMMIT)
GOBUILD = go build -ldflags="-s -w $(VAR_SETTING)" -trimpath -o $(BUILD_DIR)

release: clean darwin-amd64.zip linux-amd64.zip freebsd-amd64.zip windows-amd64.zip
release: clean darwin-amd64.zip linux-amd64.zip freebsd-amd64.zip windows-amd64.zip curl2httpie.js

cloneCurlSrc:
@echo "\033[0;32mCloning curl source code to local...\033[0m"
(ls curl_src/docs/cmdline-opts &> /dev/null) || git clone --depth=1 https://github.com/curl/curl.git curl_src
@echo

generateOptions : cloneCurlSrc
@echo "\033[0;32mGenerating curl option list...\033[0m"
rm -rf curl/optionList.go
go run cmd/generateOptions/main.go -path="./curl_src"
go fmt curl/optionList.go > /dev/null
@echo

curl2httpie.js.deps : generateOptions
@echo "\033[0;32mInstalling gopherjs and it's deps...\033[0m"
cd ../ \
&& which go1.12.16 \
|| (go get golang.org/dl/go1.12.16 && go1.12.16 download)
which gopherjs || go get github.com/gopherjs/gopherjs
@echo

.PHONY: curl2httpie.js
curl2httpie.js : curl2httpie.js.deps
@echo "\033[0;32mBuilding curl2httpie.js ...\033[0m"
GOPHERJS_GOROOT="/Users/bob/sdk/go1.12.16" gopherjs build -m -o docs/curl2httpie.js ./cmd/curl2httpie.js

initGithooks:
git config core.hooksPath .githooks

clean:
rm -rf $(BUILD_DIR)
rm -f curl2httpie
rm -f curl2httpie-*.zip
@rm -rf $(BUILD_DIR)
@rm -f curl2httpie
@rm -f curl2httpie-*.zip

test:
go test ./...

curl2httpie:
mkdir -p $(BUILD_DIR)
$(GOBUILD)

%.zip: %
@zip -du $(NAME)-$@ -j $(BUILD_DIR)/$</*
@echo "<<< ---- $(NAME)-$@"
@echo "\033[0;32m<<< ---- $(NAME)-$@\033[0m"
@echo

darwin-amd64:
darwin-amd64: generateOptions
@echo "\033[0;32mBuilding $(NAME) for $@...\033[0m"
mkdir -p $(BUILD_DIR)/$@
GOARCH=amd64 GOOS=darwin $(GOBUILD)/$@

linux-amd64:
linux-amd64: generateOptions
@echo "\033[0;32mBuilding $(NAME) for $@...\033[0m"
mkdir -p $(BUILD_DIR)/$@
GOARCH=amd64 GOOS=linux $(GOBUILD)/$@

freebsd-amd64:
freebsd-amd64: generateOptions
@echo "\033[0;32mBuilding $(NAME) for $@...\033[0m"
mkdir -p $(BUILD_DIR)/$@
GOARCH=amd64 GOOS=freebsd $(GOBUILD)/$@

windows-amd64:
windows-amd64: generateOptions
@echo "\033[0;32mBuilding $(NAME) for $@...\033[0m"
mkdir -p $(BUILD_DIR)/$@
GOARCH=amd64 GOOS=windows $(GOBUILD)/$@
59 changes: 51 additions & 8 deletions cmd/generateOptions/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -17,18 +16,62 @@ func main() {

*path = strings.TrimRight(*path, "/") + "/docs/cmdline-opts/"
options := curl.GenerateHTTPOptions(*path)
bs, err := json.Marshal(options)
if err != nil {
panic(err)
}
if len(options) < 50 {
fmt.Fprintf(os.Stderr, "Too few options found: %d\n", len(options))
os.Exit(1)
}

err = ioutil.WriteFile("./data/options.json", bs, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "writer json file: %v\n", err)
optionsCode := ""

for _, o := range options {
hasArg := "false"
if o.HasArg {
hasArg = "true"
}
tags := ""
for _, s := range o.Tags {
tags += fmt.Sprintf("`%s`,", s)
}

protocols := ""
for _, s := range o.Protocols {
protocols += fmt.Sprintf("`%s`,", s)
}

mutexed := ""
for _, s := range o.Mutexed {
mutexed += fmt.Sprintf("`%s`,", s)
}

requires := ""
for _, s := range o.Requires {
requires += fmt.Sprintf("`%s`,", s)
}

optionsCode += fmt.Sprintf(`{
Short: %d,
Long: "%s",
HasArg: %s,
Arg: "%s",
Magic: "%s",
Tags: []Tag{%s},
Protocols: []Protocol{%s},
Added: %s,
Mutexed: []LongName{%s},
Requires: []Feature{%s},
},`, o.Short, o.Long, hasArg, o.Arg, o.Magic, tags, protocols,
"`"+o.Added+"`", mutexed, requires)
}

code := fmt.Sprintf(`package curl
func init() {
optionList = []*Option{ %s }
}
`, optionsCode)

if err := ioutil.WriteFile("./curl/optionList.go", []byte(code), 0644); err != nil {
fmt.Fprintf(os.Stderr, "fail to persist curl options: %v\n", err)
os.Exit(1)
}
}
10 changes: 3 additions & 7 deletions connector/httpie.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package connector
import (
"fmt"

"encoding/json"
"github.com/dcb9/curl2httpie/curl"
"github.com/dcb9/curl2httpie/httpie"
curlTransformer "github.com/dcb9/curl2httpie/transformers/curl"
Expand Down Expand Up @@ -88,9 +87,9 @@ func Httpie2Curl(args []string) (cmdStringer fmt.Stringer, warningMessages []War
if err != nil {
return
}
data[i.K] = json.RawMessage(bytes)
data[i.K] = bytes
} else {
data[i.K] = json.RawMessage(i.V)
data[i.K] = i.V
}
}
}
Expand All @@ -101,10 +100,7 @@ func Httpie2Curl(args []string) (cmdStringer fmt.Stringer, warningMessages []War
if hasData {
if isJSONContentType {
var bs []byte
bs, err = json.Marshal(data)
if err != nil {
return
}
// FIXME
curlCmdLine.Options = append(curlCmdLine.Options, curl.NewJSONHeader(), curl.NewData(string(bs)))
} else {
fields := make([]string, 0, len(data))
Expand Down
237 changes: 0 additions & 237 deletions curl/bindata.go

This file was deleted.

13 changes: 3 additions & 10 deletions curl/curl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package curl

import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
Expand Down Expand Up @@ -199,16 +198,10 @@ func isHTTPOption(o Option) bool {
return false
}

func HTTPOptions() (options []*Option, err error) {
data, err := Asset("data/options.json")
if err != nil {
return
}
var optionList []*Option

options = make([]*Option, 0, 256)
err = json.Unmarshal(data, &options)

return
func HTTPOptions() (options []*Option, err error) {
return optionList, nil
}

func URLAndOptions(args []string) (string, []*Option, error) {
Expand Down
Loading

0 comments on commit 09b4367

Please sign in to comment.