Skip to content

Commit

Permalink
Merge pull request #205 from cabal-club/support-port
Browse files Browse the repository at this point in the history
add --port arg + preferredPort to config for custom port
  • Loading branch information
cblgh authored Jan 13, 2021
2 parents 030db17 + 9625844 commit ee3a2e2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ This will run cabal without a UI. You can use this to seed a cabal (e.g. on a VP
cabal <key> --seed
```

#### Custom port
If you have a tightly configured firewall and need to port-forward a port, the default port Cabal uses is port `13331`.
You can change this with the `--port` flag, or setting `preferredPort` in your .cabal.yml config file.

```
cabal <key> --seed --port 7331
```

## Commands
```py
/add, /cabal
Expand Down
16 changes: 15 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var usage = `Usage
Options:
--seed Start a headless seed for the specified cabal key
--port Listen for cabal traffic on the passed in port (default: 13331)
--new Start a new cabal
--nick Your nickname
Expand Down Expand Up @@ -112,6 +113,7 @@ if (!fs.existsSync(rootconfig)) {
saveConfig(rootconfig, {
cabals: [],
aliases: {},
preferredPort: 0,
cache: {},
frontend: {
messageTimeformat: defaultMessageTimeformat,
Expand All @@ -130,6 +132,7 @@ try {
}
if (!config.cabals) { config.cabals = [] }
if (!config.aliases) { config.aliases = {} }
if (!config.preferredPort) { config.preferredPort = 0 }
if (!config.cache) { config.cache = {} }
if (!config.frontend) { config.frontend = {} }
if (!config.frontend.messageTimeformat) {
Expand All @@ -149,7 +152,8 @@ const client = new Client({
maxFeeds: maxFeeds,
config: {
dbdir: archivesdir,
temp: args.temp
temp: args.temp,
preferredPort: args.port || config.preferredPort
},
commands: {
// todo: custom commands
Expand Down Expand Up @@ -367,6 +371,16 @@ if (args.alias && args.key) {
process.exit(0)
}

if (args.port) {
let port = parseInt(args.port)
if (isNaN(port) || port < 0 || port > 65535) {
logError(`${args.port} is not a valid port number`)
process.exit(1)
}
args.port = port
}


if (args.key) {
// If a key is provided, place it at the top of the keys provided from the config
cabalKeys.unshift(args.key)
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"ansi-escapes": "^4.3.1",
"cabal-client": "^6.2.5",
"cabal-client": "^6.2.7",
"chalk": "^4.0.0",
"js-yaml": "^3.13.1",
"minimist": "^1.2.5",
Expand Down

0 comments on commit ee3a2e2

Please sign in to comment.