Skip to content

Commit fbc2979

Browse files
committed
✨ Add --config option
1 parent a7d7b02 commit fbc2979

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

bin/api-to-go.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ program
1313
.argument('[body]', 'HTTP request body. specify by json string or file(json|yml).')
1414
.option('-H, --headers <string>', 'http request headers. specify by json string or file(json|yml).')
1515
.option('-X, --method <string>', 'specify request method to use.')
16+
.option('--config <string>', 'location of client config files.',"./.api-to-go.yml")
1617
.option('-D, --debug', 'enable debug mode')
1718
.action(run)
1819

src/buildPath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {loadYaml, loadConfig} = require("./common");
22

3-
function buildPath(url, configFile = "./.api-to-go.yml") {
3+
function buildPath(url, configFile) {
44
const path = _buildPath(url, configFile)
55
const pathArr = path.replacedUrl.split("/")
66
const pkg = pathArr[pathArr.length - 2].replace(/\./g, '')

src/run.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ const jsonToGo = require('../vendor/json-to-go.js');
44
const buildPath = require('./buildPath');
55
const {loadJsonOrYaml, isJsonString, loadConfig} = require("./common");
66

7+
let cliOpts
78

8-
let configFile = "./.api-to-go.yml"
9-
10-
function run(urlStr, body, cliOpts) {
11-
let comment
12-
let url
13-
let path
14-
let cfg
9+
function run(urlStr, body, options) {
10+
let comment, url, path, cfg
11+
cliOpts = options
1512

1613
let opts = {}
17-
1814
try {
1915
opts = buildOpts(body, cliOpts)
2016
} catch (e) {
@@ -29,8 +25,8 @@ function run(urlStr, body, cliOpts) {
2925
console.log()
3026
const apiUrl = urlStr.replace(/\/$/, '')
3127
url = new URL(apiUrl);
32-
cfg = loadConfig(url, configFile)
33-
path = buildPath(url)
28+
cfg = loadConfig(url, cliOpts.config)
29+
path = buildPath(url, cliOpts.config)
3430

3531
console.log(`API:`)
3632
if (cfg?.["docs"] !== undefined) console.log(` Docs: ${cfg?.["docs"]}`)
@@ -111,7 +107,7 @@ function buildContent(go, path, comment) {
111107

112108
function buildComment(url, path, method, res) {
113109
let comment = ""
114-
const cfg = loadConfig(url, configFile)
110+
const cfg = loadConfig(url, cliOpts.config)
115111
if (cfg?.["docs"] !== undefined) {
116112
comment += `\n// Docs: ${cfg?.["docs"]}`
117113
}

0 commit comments

Comments
 (0)