Example #1
0
def task_list(config, plain, print_json):
    task_groups = {}
    tasks = config.project_config.list_tasks()
    plain = plain or config.global_config.cli__plain_output

    if print_json:
        click.echo(json.dumps(tasks))
        return None

    for task in tasks:
        group = task["group"] or "Other"
        if group not in task_groups:
            task_groups[group] = []
        task_groups[group].append([task["name"], task["description"]])

    for group, tasks in task_groups.items():
        data = [["Task", "Description"]]
        data.extend(sorted(tasks))
        table = CliTable(data, group, wrap_cols=["Description"])
        table.echo(plain)

    click.echo(
        "Use "
        + click.style("cci task info <task_name>", bold=True)
        + " to get more information about a task."
    )
Example #2
0
def service_list(config, plain, print_json):
    services = (config.project_config.services if not config.is_global_keychain
                else config.global_config.services)
    configured_services = config.keychain.list_services()
    plain = plain or config.global_config.cli__plain_output

    data = [["Name", "Description", "Configured"]]
    for serv, schema in services.items():
        schema["configured"] = serv in configured_services
        data.append([serv, schema["description"], schema["configured"]])

    if print_json:
        click.echo(json.dumps(services))
        return None

    rows_to_dim = [
        row_index for row_index, row in enumerate(data) if not row[2]
    ]
    table = CliTable(
        data,
        title="Services",
        wrap_cols=["Description"],
        bool_cols=["Configured"],
        dim_rows=rows_to_dim,
    )
    table.echo(plain)
Example #3
0
def test_table_pretty_output_windows(sample_data, pretty_output_win,
                                     fixture_key):
    instance = CliTable(sample_data[fixture_key])
    instance.INNER_BORDER = False
    table = instance.pretty_table().strip()
    expected = pretty_output_win[fixture_key].strip()
    assert expected == table
Example #4
0
def test_table_pretty_echo(sample_data, pretty_output, fixture_key, capsys):
    instance = CliTable(sample_data[fixture_key])
    instance.INNER_BORDER = False
    instance.echo(plain=False)

    captured = capsys.readouterr()
    expected = pretty_output[fixture_key] + "\n\n"
    assert expected == captured.out
Example #5
0
 def _log_failures(self, results):
     """Logs failures using CliTable"""
     table_title = "Failed Apex Tests"
     table_data = self._get_table_data(results)
     table = CliTable(table_data,
                      table_title,
                      wrap_cols=["Message", "Stacktrace"])
     table.echo()
Example #6
0
def test_table_plain_fallback(sample_data, plain_output, capsys):
    with mock.patch("cumulusci.cli.ui.CliTable.pretty_table") as pretty_table:
        pretty_table.side_effect = UnicodeEncodeError("cp1542", u"", 42, 43,
                                                      "Fake exception")
        instance = CliTable(sample_data["service_list"])
        instance.echo(plain=False)
        captured = capsys.readouterr()
        # append newlines because echo adds them to account for task tables
        assert plain_output["service_list"] == captured.out
Example #7
0
def org_info(config, org_name, print_json):
    try:
        org_name, org_config = config.get_org(org_name)
        org_config.refresh_oauth_token(config.keychain)
    except OrgNotFound as e:
        raise click.ClickException(e)

    if print_json:
        click.echo(
            json.dumps(
                org_config.config,
                sort_keys=True,
                indent=4,
                default=str,
                separators=(",", ": "),
            ))
    else:
        UI_KEYS = [
            "config_file",
            "config_name",
            "created",
            "date_created",
            "days",
            "default",
            "email_address",
            "instance_url",
            "is_sandbox",
            "namespaced",
            "org_id",
            "org_type",
            "password",
            "scratch",
            "scratch_org_type",
            "set_password",
            "sfdx_alias",
            "username",
        ]
        keys = [key for key in org_config.config.keys() if key in UI_KEYS]
        pairs = [[key, str(org_config.config[key])] for key in keys]
        pairs.append(["api_version", org_config.latest_api_version])
        pairs.sort()
        table_data = [["Key", "Value"]]
        table_data.extend([[click.style(key, bold=True), value]
                           for key, value in pairs])
        table = CliTable(table_data, wrap_cols=["Value"])
        table.echo()

        if org_config.scratch and org_config.expires:
            click.echo("Org expires on {:%c}".format(org_config.expires))

    # Save the org config in case it was modified
    config.keychain.set_org(org_config)
Example #8
0
def org_list(config, plain):
    plain = plain or config.global_config.cli__plain_output
    header = ["Name", "Default", "Username", "Expires"]
    persistent_data = [header]
    scratch_data = [header[:2] + ["Days", "Expired", "Config", "Domain"]]
    org_configs = {
        org: config.project_config.keychain.get_org(org)
        for org in config.project_config.keychain.list_orgs()
    }
    rows_to_dim = []
    for org, org_config in org_configs.items():
        row = [org, org_config.default]
        if isinstance(org_config, ScratchOrgConfig):
            org_days = org_config.format_org_days()
            if org_config.expired:
                domain = ""
            else:
                instance_url = org_config.config.get("instance_url", "")
                domain = urlparse(instance_url).hostname or ""
                if domain:
                    domain = domain.replace(".my.salesforce.com", "")
            row.extend([
                org_days, not org_config.active, org_config.config_name, domain
            ])
            scratch_data.append(row)
        else:
            username = org_config.config.get(
                "username", org_config.userinfo__preferred_username)
            row.append(username)
            row.append(org_config.expires or "Unknown")
            persistent_data.append(row)

    rows_to_dim = [
        row_index for row_index, row in enumerate(scratch_data) if row[3]
    ]
    scratch_table = CliTable(scratch_data,
                             title="Scratch Orgs",
                             bool_cols=["Default"],
                             dim_rows=rows_to_dim)
    scratch_table.stringify_boolean_col(col_name="Expired", true_str=CROSSMARK)
    scratch_table.echo(plain)

    wrap_cols = ["Username"] if not plain else None
    persistent_table = CliTable(
        persistent_data,
        title="Connected Orgs",
        wrap_cols=wrap_cols,
        bool_cols=["Default"],
    )
    persistent_table.echo(plain)
Example #9
0
def test_table_wrap_cols(max_width, sample_data):
    width = 80
    max_width.return_value = width
    data = sample_data["service_list"]
    data[1][1] = data[1][1] + "a" * 256
    instance = CliTable(data, wrap_cols=["Description"])
    assert all((len(line) for line in instance._table.table_data[1][1].split("\n")))
Example #10
0
def flow_list(config, plain, print_json):
    plain = plain or config.global_config.cli__plain_output
    flows = config.project_config.list_flows()

    if print_json:
        click.echo(json.dumps(flows))
        return None

    data = [["Name", "Description"]]
    data.extend([flow["name"], flow["description"]] for flow in flows)

    table = CliTable(data, title="Flows", wrap_cols=["Description"])
    table.echo(plain=plain)

    click.echo("Use " + click.style("cci flow info <flow_name>", bold=True) +
               " to get more information about a flow.")
 def _log_success_message(self, subrequests):
     table_data = [["ReferenceId", "Success"]]
     table_data.extend(
         [sub["referenceId"], self._http_ok(sub["httpStatusCode"])]
         for sub in subrequests
     )
     table = CliTable(table_data, bool_cols=["Success"], title="Subrequest Results")
     self.logger.info("\n" + str(table))
Example #12
0
def service_info(config, service_name, plain):
    try:
        plain = plain or config.global_config.cli__plain_output
        service_config = config.keychain.get_service(service_name)
        service_data = [["Key", "Value"]]
        service_data.extend([[click.style(k, bold=True),
                              str(v)]
                             for k, v in service_config.config.items()])
        wrap_cols = ["Value"] if not plain else None
        service_table = CliTable(service_data,
                                 title=service_name,
                                 wrap_cols=wrap_cols)
        service_table._table.inner_heading_row_border = False
        service_table.echo(plain)
    except ServiceNotConfigured:
        click.echo(
            "{0} is not configured for this project.  Use service connect {0} to configure."
            .format(service_name))
Example #13
0
def test_table_dim_rows(sample_data):
    data = sample_data["service_list"]
    instance = CliTable(data, dim_rows=[1])
    assert all(
        (
            cell.startswith("\x1b[2m") and cell.endswith("\x1b[0m")
            for cell in instance._table.table_data[1]
        )
    )
Example #14
0
def org_list(config, plain):
    plain = plain or config.global_config.cli__plain_output
    header = ["Name", "Default", "Username"]
    persistent_data = [header]
    scratch_data = [header[:2] + ["Days", "Expired", "Config"]]

    org_configs = OrderedDict(
        (org, config.project_config.keychain.get_org(org))
        for org in config.project_config.keychain.list_orgs())

    rows_to_dim = []
    for org, org_config in org_configs.items():
        row = [org, org_config.default]
        if isinstance(org_config, ScratchOrgConfig):
            org_days = org_config.format_org_days()
            row.extend([org_days, org_config.expired, org_config.config_name])
            scratch_data.append(row)
        else:
            username = org_config.config.get(
                "username", org_config.userinfo__preferred_username)
            row.append(username)
            persistent_data.append(row)

    rows_to_dim = [
        row_index for row_index, row in enumerate(scratch_data)
        if row[3] or not org_configs[row[0]].date_created
    ]
    scratch_table = CliTable(scratch_data,
                             title="Scratch Orgs",
                             bool_cols=["Default"],
                             dim_rows=rows_to_dim)
    scratch_table.stringify_boolean_col(col_name="Expired", true_str=CROSSMARK)
    scratch_table.echo(plain)

    wrap_cols = ["Username"] if not plain else None
    persistent_table = CliTable(
        persistent_data,
        title="Persistent Orgs",
        wrap_cols=wrap_cols,
        bool_cols=["Default"],
    )
    persistent_table.echo(plain)
 def _log_exception_message(self, subrequests):
     table_data = [["ReferenceId", "Message"]]
     table_data.extend(
         [sub["referenceId"], body["message"]]
         for sub in subrequests
         for body in sub["body"]
         if body.get("message") != API_ROLLBACK_MESSAGE
     )
     table = CliTable(table_data, wrap_cols=["Message"])
     self.logger.error("The request failed with the following message(s):\n\n")
     self.logger.error("\n" + str(table))
Example #16
0
def test_table_stringify_booleans(sample_data):
    data = sample_data["service_list"]
    data[1][2] = True
    instance = CliTable(data, bool_cols=["Configured"])
    assert CHECKMARK in instance._table.table_data[1]
    assert CliTable.PICTOGRAM_FALSE in instance._table.table_data[2]
Example #17
0
def test_table_plain_echo(sample_data, plain_output, fixture_key, capsys):
    instance = CliTable(sample_data[fixture_key])
    instance.echo(plain=True)
    captured = capsys.readouterr()
    expected = plain_output[fixture_key]
    assert expected == captured.out
Example #18
0
def test_table_pretty_output(sample_data, pretty_output, fixture_key):
    instance = CliTable(sample_data[fixture_key])
    assert pretty_output[fixture_key] == instance.table.table
Example #19
0
def test_table_plain_output(sample_data, plain_output, fixture_key, capsys):
    instance = CliTable(sample_data[fixture_key])
    table = instance.ascii_table()
    expected = plain_output[fixture_key].strip()
    assert expected == table
Example #20
0
def test_table_pretty_output_windows(sample_data, pretty_output_win,
                                     fixture_key):
    instance = CliTable(sample_data[fixture_key])
    assert pretty_output_win[fixture_key].strip() == instance.table.table
Example #21
0
def test_table_pretty_output(sample_data, pretty_output, fixture_key):
    instance = CliTable(sample_data[fixture_key])
    instance.INNER_BORDER = False
    table = instance.pretty_table()
    expected = pretty_output[fixture_key] + "\n"
    assert expected == table
Example #22
0
def test_table_plain_output(sample_data, plain_output, fixture_key, capsys):
    instance = CliTable(sample_data[fixture_key])
    instance.ascii_table()
    captured = capsys.readouterr()
    expected = plain_output[fixture_key] + "\n\n"
    assert expected == captured.out
Example #23
0
 def do_vars(self, arg=None):
     """Print the value of all known variables"""
     vars = self.builtin.get_variables()
     vars = [["Variable", "Value"]
             ] + [list(x) for x in sorted(vars.items())]
     CliTable(vars).echo()