Skip to content

Commit ffc453f

Browse files
author
Jose Constela
committed
Allow to specify Tideflow URL via cli
1 parent 6c51aeb commit ffc453f

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ npm i -g @tideflowio/tideflow-agent
1616
Usage: index [options]
1717

1818
Options:
19-
-v, --version output the version number
20-
-c, --concurrency [concurrency] Max number of jobs the agent should process concurrently
21-
-t, --token [token] Authentication token
22-
--noupdate Opt-out of update version check
23-
-h, --help output usage information
19+
-v, --version output the version number
20+
-c, --concurrency [concurrency] Max number of jobs the agent should process concurrently
21+
-t, --token [token] Authentication token
22+
-u, --url [url] Tideflow url
23+
--noupdate Opt-out of update version check
24+
-h, --help output usage information
2425

2526
Examples:
2627
$ tideflow-agent --help
@@ -29,14 +30,14 @@ npm i -g @tideflowio/tideflow-agent
2930
You can also run the agent without installing it, via npx.
3031

3132
```bash
32-
npx @tideflowio/tideflow-agent -t [token]
33+
npx @tideflowio/tideflow-agent -t [token] -u tideflow.example.com
3334
```
3435

3536
## Environment variables
3637

3738
```bash
3839
# Specify the URL to connect to the Tideflow's platform.
39-
# Optional. Defaults to localhost:1337
40+
# Optional. Defaults to localhost:1337 if no -u parameter set
4041
# Example: http://subdomain.example.com:1337
4142
TF_AGENT_URL
4243
```

agent.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const pjson = require('./package.json')
22
const io = require('socket.io-client')
33
const colors = require('colors')
4+
const url = require('url')
45
const pretty = require('./helpers/pretty')
56
const runner = require('./runner')
67
const os = require('os')
@@ -20,12 +21,16 @@ module.exports.exec = (program) => {
2021

2122
let agent = {}
2223

24+
const URL = program.url || process.env.TF_AGENT_URL || 'http://localhost:1337'
25+
26+
const parse = url.parse(URL)
27+
if (!parse.hostname) { throw new Error(`"${URL}" is not a valid url`) }
28+
2329
// Shows welcome messages
24-
console.log(pretty.logo())
30+
console.log(pretty.logo(pjson))
2531
console.log(` || Tideflow.io - agent ${pjson.version}`.blue)
2632
console.log(` || Using ${concurrency} as concurrency`.yellow)
27-
28-
const URL = process.env.TF_AGENT_URL || 'http://localhost:1337'
33+
console.log(` || Target URL ${URL}`.yellow)
2934

3035
const socket = io(`${URL}?token=${program.token}`)
3136

helpers/pretty.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* Returns a pretty logo for terminal
33
*/
4-
module.exports.logo = () => {
4+
module.exports.logo = (pjson) => {
55
return `
66
_ _ _ ___ _ _
77
| |_|_|_| |___| _| |___ _ _ _ |_|___
88
| _| | . | -_| _| | . | | | |_| | . |
9-
|_| |_|___|___|_| |_|___|_____|_|_|___|
9+
|_| |_|___|___|_| |_|___|_____|_|_|___| ${pjson.version}
1010
`
1111
}

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
'use strict'
33
const program = require('commander')
4+
const url = require('url')
45
const os = require('os')
56
const pkg = require('./package.json')
67

@@ -15,6 +16,11 @@ program
1516
.option('-t, --token [token]', 'Authentication token', (v) => {
1617
return v || process.env.TIDEFLOWIO_AGENT_TOKEN
1718
})
19+
.option('-u, --url [url]', 'Tideflow url', (v) => {
20+
const parse = url.parse(v)
21+
if (!parse.hostname) { throw new Error(`"${URL}" is not a valid url`) }
22+
return v
23+
})
1824
.option('--noupdate', 'Opt-out of update version check')
1925

2026
// must be before .parse() since
@@ -23,7 +29,7 @@ program
2329
program.on('--help', function(){
2430
console.log('')
2531
console.log('Examples:')
26-
console.log(' $ tideflow-agent -t agent-auth-token')
32+
console.log(' $ tideflow-agent -u http://mytideflow.example.com -t agent-auth-token')
2733
console.log(' $ tideflow-agent -c 16 -t agent-auth-token')
2834
console.log(' $ tideflow-agent --help')
2935
console.log(' $ tideflow-agent -h')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tideflowio/tideflow-agent",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Tideflow.io's agent",
55
"main": "index.js",
66
"keywords": [

0 commit comments

Comments
 (0)