public async run()

in src/commands/analytics/audience.ts [76:119]


  public async run(client: AppCenterClient): Promise<CommandResult> {
    const app: DefaultApp = this.app;

    const appVersion = this.getAppVersion();
    const appBuild = this.getAppBuild();
    const startDate = parseDate(
      this.startDate,
      new Date(new Date().setHours(0, 0, 0, 0)),
      `start date value ${this.startDate} is not a valid date string`
    );
    const endDate = parseDate(this.endDate, new Date(), `end date value ${this.endDate} is not a valid date string`);

    if (!this.devices && !this.countries && !this.languages && !this.activeUsers) {
      // when no switches are specified, all the data should be shown
      this.devices = this.countries = this.languages = this.activeUsers = true;
    }

    const promises: Array<Promise<void>> = [];
    const statistics: IStatisticsObject = {};

    if (this.devices) {
      promises.push(this.loadDevicesStatistics(statistics, client, app, startDate, endDate, appVersion));
    }

    if (this.countries) {
      promises.push(this.loadCountriesStatistics(statistics, client, app, startDate, endDate, appVersion));
    }

    if (this.languages) {
      promises.push(this.loadLanguagesStatistics(statistics, client, app, startDate, endDate, appVersion));
    }

    if (this.activeUsers && appBuild) {
      promises.push(this.loadActiveUsersStatistics(statistics, client, app, startDate, endDate, appVersion, appBuild));
    } else if (this.activeUsers) {
      out.text("Warning: Please provide app version to get active users statistics.");
    }

    await out.progress("Loading statistics...", Promise.all(promises));

    this.outputStatistics(statistics);

    return success();
  }