Skip to content

Commit

Permalink
drop dependency cli package
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Sep 24, 2021
1 parent 7e6bf7a commit df37f22
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 676 deletions.
22 changes: 8 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ VERSION = $(shell grep '"version":' codemeta.json | cut -d \" -f 4)

BRANCH = $(shell git branch | grep '* ' | cut -d\ -f 2)

PKGASSETS = $(shell which pkgassets)

CODEMETA2CFF = $(shell which codemeta2cff)

Expand All @@ -32,16 +31,12 @@ version.go: .FORCE

crossrefapi$(EXT): bin/crossrefapi$(EXT)

cmd/crossrefapi/assets.go:
pkgassets -o cmd/crossrefapi/assets.go -p main -ext=".md" -strip-prefix="/" -strip-suffix=".md" Examples how-to Help docs/crossrefapi
git add cmd/crossrefapi/assets.go

bin/crossrefapi$(EXT): crossrefapi.go cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
go build -o bin/crossrefapi$(EXT) cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
bin/crossrefapi$(EXT): crossrefapi.go cmd/crossrefapi/crossrefapi.go
go build -o bin/crossrefapi$(EXT) cmd/crossrefapi/crossrefapi.go


install:
env GOBIN=$(GOPATH)/bin go install cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOBIN=$(GOPATH)/bin go install cmd/crossrefapi/crossrefapi.go

website: page.tmpl README.md nav.md INSTALL.md LICENSE css/site.css
bash mk-website.bash
Expand All @@ -60,7 +55,6 @@ lint:
golint cmd/crossrefapi/crossrefapi.go

clean:
if [ "$(PKGASSETS)" != "" ]; then bash rebuild-assets.bash; fi
if [ -f index.html ]; then rm *.html; fi
if [ -d bin ]; then rm -fR bin; fi
if [ -d dist ]; then rm -fR dist; fi
Expand All @@ -73,31 +67,31 @@ man: build

dist/linux-amd64:
mkdir -p dist/bin
env GOOS=linux GOARCH=amd64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOOS=linux GOARCH=amd64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go
cd dist && zip -r $(PROJECT)-$(VERSION)-linux-amd64.zip README.md LICENSE INSTALL.md bin/*
rm -fR dist/bin

dist/windows-amd64:
mkdir -p dist/bin
env GOOS=windows GOARCH=amd64 go build -o dist/bin/crossrefapi.exe cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOOS=windows GOARCH=amd64 go build -o dist/bin/crossrefapi.exe cmd/crossrefapi/crossrefapi.go
cd dist && zip -r $(PROJECT)-$(VERSION)-windows-amd64.zip README.md LICENSE INSTALL.md bin/*
rm -fR dist/bin

dist/macos-amd64:
mkdir -p dist/bin
env GOOS=darwin GOARCH=amd64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOOS=darwin GOARCH=amd64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go
cd dist && zip -r $(PROJECT)-$(VERSION)-macos-amd64.zip README.md LICENSE INSTALL.md bin/*
rm -fR dist/bin

dist/macos-arm64:
mkdir -p dist/bin
env GOOS=darwin GOARCH=arm64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOOS=darwin GOARCH=arm64 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go
cd dist && zip -r $(PROJECT)-$(VERSION)-macos-arm64.zip README.md LICENSE INSTALL.md bin/*
rm -fR dist/bin

dist/raspbian-arm7:
mkdir -p dist/bin
env GOOS=linux GOARCH=arm GOARM=7 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go cmd/crossrefapi/assets.go
env GOOS=linux GOARCH=arm GOARM=7 go build -o dist/bin/crossrefapi cmd/crossrefapi/crossrefapi.go
cd dist && zip -r $(PROJECT)-$(VERSION)-raspbian-arm7.zip README.md LICENSE INSTALL.md bin/*
rm -fR dist/bin

Expand Down
12 changes: 0 additions & 12 deletions cmd/crossrefapi/assets.go

This file was deleted.

84 changes: 31 additions & 53 deletions cmd/crossrefapi/crossrefapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,47 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"os"
"path"
"strings"

// Caltech Library packages
"github.com/caltechlibrary/cli"
"github.com/caltechlibrary/crossrefapi"
)

var (
synopsis = `
_%s_ can retrieve "types" and "works" from the CrossRef API
`
description = `
_%s_ is a command line utility to retrieve "types" and "works" objects
USAGE
{appName} [OPTIONS] DOI
SYNOPSIS
{appName} can retrieve "types" and "works" from the CrossRef API
DETAIL
{appName} is a command line utility to retrieve "types" and "works" objects
from the CrossRef API. It follows the etiquette suggested at
` + "```" + `
https://github.com/CrossRef/rest-api-doc#etiquette
` + "```" + `
`
examples = `
Return the types of objects in CrossRef (e.g. journal articles)
` + "```" + `
%s -mailto="[email protected]" types
` + "```" + `
{appName} -mailto="[email protected]" types
Return the works for the doi "10.1037/0003-066x.59.1.29"
` + "```" + `
%s -mailto="[email protected]" \
{appName} -mailto="[email protected]" \
works "10.1037/0003-066x.59.1.29"
` + "```" + `
`

license = `
%s %s
{appName} {version}
Copyright (c) 2021, Caltech
All rights not granted herein are expressly reserved by Caltech.
Expand All @@ -75,8 +77,6 @@ Redistribution and use in source and binary forms, with or without modification,
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`
// Standard Options
generateMarkdown bool
generateManPage bool
showHelp bool
showLicense bool
showVersion bool
Expand Down Expand Up @@ -106,62 +106,40 @@ func pop(args []string) (string, []string) {

func main() {
appName := path.Base(os.Args[0])
app := cli.NewCli(crossrefapi.Version)
app.SetParams("types|works DOI")

app.AddHelp("synopsis", []byte(fmt.Sprintf(synopsis, appName)))
app.AddHelp("description", []byte(fmt.Sprintf(description, appName)))
app.AddHelp("examples", []byte(fmt.Sprintf(examples, appName, appName)))
app.AddHelp("license", []byte(fmt.Sprintf(license, appName, crossrefapi.Version)))
for k, v := range Help {
app.AddHelp(k, v)
}
flagSet := flag.NewFlagSet(appName, flag.ContinueOnError)


// Standard Options
app.BoolVar(&showHelp, "h,help", false, "display help")
app.BoolVar(&showLicense, "l,license", false, "display license")
app.BoolVar(&showVersion, "v,version", false, "display app version")
app.BoolVar(&generateMarkdown, "generate-markdown", false, "output documentation in Markdown")
app.BoolVar(&generateManPage, "generate-manpage", false, "generate man page")
flagSet.BoolVar(&showHelp, "h", false, "display help")
flagSet.BoolVar(&showHelp, "h,help", false, "display help")
flagSet.BoolVar(&showLicense, "license", false, "display license")
flagSet.BoolVar(&showVersion, "version", false, "display app version")

// Application Options
app.StringVar(&mailto, "m,mailto", "", "set the mailto value for API access")
flagSet.StringVar(&mailto, "m", "", "set the mailto value for API access")
flagSet.StringVar(&mailto, "m,mailto", "", "set the mailto value for API access")

app.Parse()
args := app.Args()
flagSet.Parse(os.Args)
args := flagSet.Args()

if generateMarkdown {
app.GenerateMarkdown(os.Stdout)
os.Exit(0)
}
if generateManPage {
app.GenerateManPage(os.Stdout)
os.Exit(0)
}

if showHelp {
if showHelp {
if len(args) > 0 {
fmt.Fprintf(os.Stdout, app.Help(args...))
} else {
app.Usage(os.Stdout)
}
os.Exit(0)
}
crossrefapi.DisplayUsage(os.Stdout, appName, flagSet, description, examples, license)
os.Exit(0)
}

if showLicense {
fmt.Fprintln(os.Stdout, app.License())
crossrefapi.DisplayLicense(os.Stdout, appName, license)
os.Exit(0)
}

if showVersion {
fmt.Fprintln(os.Stdout, app.Version())
crossrefapi.DisplayVersion(os.Stdout, appName)
os.Exit(0)
}

if len(args) < 1 {
app.Usage(os.Stderr)
crossrefapi.DisplayUsage(os.Stderr, appName, flagSet, description, examples, license)
os.Exit(1)
}

Expand Down
34 changes: 34 additions & 0 deletions crossrefapiCli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package crossrefapi

import (
"flag"
"fmt"
"io"
"strings"
)

func DisplayLicense(out io.Writer, appName string, license string) {
fmt.Fprintf(out, strings.ReplaceAll(strings.ReplaceAll(license, "{appName}", appName), "{version}", Version))
}

func DisplayVersion(out io.Writer, appName string) {
fmt.Fprintf(out, "\n%s %s\n", appName, Version)
}

func DisplayUsage(out io.Writer, appName string, flagSet *flag.FlagSet, description string, examples string, license string) {
// Convert {appName} and {version} in description
if description != "" {
fmt.Fprintf(out, strings.ReplaceAll(description, "{appName}", appName))
}
flagSet.SetOutput(out)
flagSet.PrintDefaults()

if examples != "" {
fmt.Fprintf(out, strings.ReplaceAll(examples, "{appName}", appName))
}
if license != "" {
DisplayLicense(out, appName, license)
}
DisplayVersion(out, appName)
}

11 changes: 0 additions & 11 deletions gen-usage-pages.bash

This file was deleted.

5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/caltechlibrary/crossrefapi

go 1.17

require (
github.com/caltechlibrary/cli v0.0.18
github.com/caltechlibrary/doitools v0.0.0-20190910184449-c524f84bb2b3
)
require github.com/caltechlibrary/doitools v0.0.0-20190910184449-c524f84bb2b3
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/caltechlibrary/cli v0.0.18 h1:Z1NjhJ2ar2lWCFlA00wVDa5j0qnsL2XeI/qtgX2wOXU=
github.com/caltechlibrary/cli v0.0.18/go.mod h1:9crFPycCNeyTWautZ0t/YjaW8Clsr9uQZfq/SNNwhak=
github.com/caltechlibrary/doitools v0.0.0-20190910184449-c524f84bb2b3 h1:CPVAtgb3KfFDvN/LA6lk3JGT76tVC+PohQWynTkS52s=
github.com/caltechlibrary/doitools v0.0.0-20190910184449-c524f84bb2b3/go.mod h1:dBtDM+sEd5W27XSuPTcYGUNmkO9PWJ4JMh5bW1EO8L0=
85 changes: 0 additions & 85 deletions index.html

This file was deleted.

Loading

0 comments on commit df37f22

Please sign in to comment.