Skip to content

Commit

Permalink
Merge pull request #217 from dalcde/url
Browse files Browse the repository at this point in the history
Make url parameter optional when generating registration
  • Loading branch information
Half-Shot authored Sep 3, 2020
2 parents bbac784 + 90a1e74 commit bc8edb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/217.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make url parameter optional when generating registration.
25 changes: 16 additions & 9 deletions src/components/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ interface CliOpts<ConfigType extends Record<string, unknown>> {
enableRegistration?: boolean;
enableLocalpart: boolean;
port: number;
noUrl?: boolean;
}

interface CliArgs {
"generate-registration": boolean;
config: string;
url: string;
url?: string;
localpart: string;
port: number;
file: string;
Expand Down Expand Up @@ -71,6 +72,8 @@ export class Cli<ConfigType extends Record<string, unknown>> {
* (string) or the parsed schema file (Object).
* @param opts.bridgeConfig.defaults The default options for the
* config file.
* @param opts.noUrl Don't ask user for appservice url when generating
* registration.
* @param opts.enableRegistration Enable '--generate-registration'.
* Default True.
* @param opts.registrationPath The path to write the registration
Expand Down Expand Up @@ -149,11 +152,16 @@ export class Cli<ConfigType extends Record<string, unknown>> {
}

if (this.opts.enableRegistration && this.args["generate-registration"]) {
if (!this.args.url) {
if (!this.args.url && !this.opts.noUrl) {
this.printHelp();
console.log("Missing --url [-u]");
process.exit(1);
}
else if (this.args.url && this.opts.noUrl) {
this.printHelp();
console.log("--url [-u] is not valid option for this bridge.");
process.exit(1);
}
if (this.args.port) {
this.printHelp();
console.log("--port [-p] is not valid when generating a registration file.");
Expand Down Expand Up @@ -220,11 +228,8 @@ export class Cli<ConfigType extends Record<string, unknown>> {
return validator.validate(cfg, this.opts.bridgeConfig.defaults) as ConfigType;
}

private generateRegistration(appServiceUrl: string, localpart: string) {
if (!appServiceUrl) {
throw Error("Missing app service URL");
}
let reg = new AppServiceRegistration(appServiceUrl);
private generateRegistration(appServiceUrl: string | undefined, localpart: string) {
let reg = new AppServiceRegistration(appServiceUrl || "");
if (localpart) {
reg.setSenderLocalpart(localpart);
}
Expand Down Expand Up @@ -282,8 +287,10 @@ export class Cli<ConfigType extends Record<string, unknown>> {
if (this.opts.enableRegistration) {
help["--generate-registration -r"] = "Create a registration YAML file " +
"for this application service";
help["--url -u"] = "Registration Option. Required if -r is set. The URL " +
"where the application service is listening for HS requests";
if (!this.opts.noUrl) {
help["--url -u"] = "Registration Option. Required if -r is set. The " +
"URL where the application service is listening for HS requests";
}
if (this.opts.enableLocalpart) {
help["--localpart -l"] = "Registration Option. Valid if -r is set. " +
"The user_id localpart to assign to the AS.";
Expand Down

0 comments on commit bc8edb9

Please sign in to comment.