Skip to content

Commit 2da934a

Browse files
committed
added go.mod, codemeta.json, update_version.py
1 parent 7ae55dd commit 2da934a

File tree

4 files changed

+144
-4
lines changed

4 files changed

+144
-4
lines changed

cmds/jsoncols/jsoncols.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ Would yield
7878
generateMarkdownDocs bool
7979
quiet bool
8080
newLine bool
81+
prettyPrint bool
8182

8283
// Application Specific Options
8384
runInteractive bool
8485
csvOutput bool
8586
delimiter = ","
8687
expressions []string
8788
quote bool
88-
pretty bool
8989
)
9090

9191
func main() {
@@ -122,7 +122,7 @@ func main() {
122122
app.BoolVar(&csvOutput, "csv", false, "output as CSV or other flat delimiter row")
123123
app.StringVar(&delimiter, "d,delimiter", delimiter, "set the delimiter for multi-field csv output")
124124
app.BoolVar(&quote, "quote", true, "quote strings and JSON notation")
125-
app.BoolVar(&pretty, "p,pretty", false, "pretty print JSON output")
125+
app.BoolVar(&prettyPrint, "p,pretty", false, "pretty print JSON output")
126126

127127
// Parse Environment and Options
128128
app.Parse()
@@ -192,7 +192,7 @@ func main() {
192192
case json.Number:
193193
row = append(row, result.(json.Number).String())
194194
default:
195-
if pretty {
195+
if prettyPrint {
196196
src, err = json.MarshalIndent(result, "", " ")
197197
} else {
198198
src, err = json.Marshal(result)
@@ -236,7 +236,7 @@ func main() {
236236
case json.Number:
237237
fmt.Fprintf(app.Out, "%s", result.(json.Number).String())
238238
default:
239-
if pretty {
239+
if prettyPrint {
240240
src, err = json.MarshalIndent(result, "", " ")
241241
} else {
242242
src, err = json.Marshal(result)

codemeta.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
3+
"@type": "SoftwareSourceCode",
4+
"description": "A set of command line tools for working with CSV, Excel Workbooks, Google Sheets, JSON and structured text documents.",
5+
"name": "datatools",
6+
"codeRepository": "https://github.com/caltechlibrary/datatools",
7+
"issueTracker": "https://github.com/caltechlibrary/datatools/issues",
8+
"license": "https://data.caltech.edu/license",
9+
"version": "0.0.24",
10+
"author": [
11+
{
12+
"@type": "Person",
13+
"givenName": "Robert",
14+
"familyName": "Doiel",
15+
"affiliation": "Caltech Library",
16+
"email": "[email protected]",
17+
"@id": "https://orcid.org/0000-0003-0900-6903"
18+
}
19+
],
20+
"developmentStatus": "active",
21+
"downloadUrl": "https://github.com/caltechlibrary/datatools/archive/v0.0.24.zip",
22+
"keywords": [
23+
"csv",
24+
"json",
25+
"xlsx",
26+
"golang",
27+
"bash"
28+
],
29+
"maintainer": "https://orcid.org/0000-0003-0900-6903",
30+
"programmingLanguage": [
31+
"Go",
32+
"Python"
33+
]
34+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module "github.com/caltechlibrary/datatools"
2+
3+
require "github.com/dexyk/stringosim" v0.0.0-20170922105913-9d0b3e91a842

update_version.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python3
2+
3+
# Project values
4+
PROJECT_GO = "dataset.go"
5+
CODEMETA_JSON = "codemeta.json"
6+
7+
#
8+
# No changes below this line
9+
#
10+
import sys
11+
import os
12+
import json
13+
14+
def inc_patch_no(v = "0.0.0"):
15+
"""inc_patch_no takes a symvar and increments the right most value in the dot touple"""
16+
parts = v.split(".")
17+
if len(parts) == 3:
18+
#major_no = parts[0]
19+
#minor_no = parts[1]
20+
patch_no = int(parts[2])
21+
patch_no += 1
22+
parts[2] = str(patch_no)
23+
return ".".join(parts)
24+
else:
25+
return v
26+
27+
def update_codemeta_json(codemeta_json, current_version, next_version):
28+
with open(codemeta_json, mode = "r", encoding = "utf-8") as f:
29+
src = f.read()
30+
meta = json.loads(src)
31+
meta["version"] = next_version
32+
downloadURL = meta["downloadUrl"]
33+
meta["downloadUrl"] = downloadURL.replace(current_version, next_version)
34+
src = json.dumps(meta, indent = 4)
35+
with open(codemeta_json, mode = "w", encoding = "utf-8") as f:
36+
f.write(src)
37+
print(f"updated {codemeta_json} version from {current_version} to {next_version}")
38+
return True
39+
40+
def update_project_go(project_go, current_version, next_version):
41+
with open(project_go, mode = "r", encoding = "utf-8") as f:
42+
src = f.read()
43+
txt = src.replace(f"Version = `v{current_version}`", f"Version = `v{next_version}`")
44+
with open(project_go, mode = "w", encoding = "utf-8") as f:
45+
f.write(txt)
46+
print(f"updated {project_go} Version from v{current_version} to v{next_version}")
47+
return True
48+
49+
def usage(app_name):
50+
app_name = os.path.basename(app_name)
51+
print(f"""
52+
USAGE: {app_name} OPTIONS
53+
54+
SYNOPSIS
55+
56+
{app_name} shows or sets the proposed new value for a version number.
57+
By defaut it proposes a increment in the patch no of a symvar string.
58+
If the -y, --yes option is included it will commit the change in patch
59+
number to the codemeta.json and project's go file.
60+
61+
OPTIONS
62+
63+
--set VALUE explicitly set the value of the new version string
64+
-y, --yes commit the changes proposed to the Codemeta and Go file.
65+
""")
66+
67+
#
68+
# Main processing
69+
#
70+
def main(args):
71+
if ("-h" in args) or ("-help" in args) or ("--help" in args):
72+
usage(args[0])
73+
sys.exit(0)
74+
current_version = ""
75+
next_version = ""
76+
meta = {}
77+
with open(CODEMETA_JSON,"r") as f:
78+
src = f.read()
79+
meta = json.loads(src)
80+
81+
current_version = meta["version"]
82+
83+
if ("--set" in args):
84+
i = args.index("--set")
85+
i += 1
86+
if len(args) < i:
87+
print("Missing new version number after set", args)
88+
sys.exit(1)
89+
next_version = args[i]
90+
if next_version[0] == "v":
91+
next_version = next_version[1:]
92+
else:
93+
next_version = inc_patch_no(current_version)
94+
95+
if ("--yes" in args) or ("-yes" in args) or ("-y" in args):
96+
update_codemeta_json(CODEMETA_JSON, current_version, next_version)
97+
update_project_go(PROJECT_GO, current_version, next_version)
98+
else:
99+
print("current version:", current_version)
100+
print("proposed version:", next_version)
101+
102+
if __name__ == "__main__":
103+
main(sys.argv[:])

0 commit comments

Comments
 (0)