-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
74 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 | ||
|
@@ -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) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.