Skip to content

Commit

Permalink
#1 --no-color option added
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Jan 12, 2024
1 parent 79cebe8 commit 6445f81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Options:
-t, --token TEXT JIRA_TOKEN value
-m, --email TEXT JIRA_EMAIL value
-s, --server TEXT JIRA_SERVER value
--spin / --no-spin Control the spinner
--spin / --no-spin Control the spinner [default: spin]
--color / --no-color Control colors [default: color]
-h, --help Show this message and exit
--version Show the version and exit
Expand Down
11 changes: 8 additions & 3 deletions src/dzira/dzira.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
REQUIRED_KEYS = "JIRA_SERVER", "JIRA_EMAIL", "JIRA_TOKEN", "JIRA_PROJECT_KEY"

use_spinner = True
use_color = True


def c(*args):
Expand All @@ -37,7 +38,9 @@ def c(*args):
("^blue", 94),
("^magenta", 95),
("^cyan", 96))}
return "".join([C.get(a, a) for a in args]) + C["^reset"]
if use_color:
return "".join([C.get(a, a) for a in args]) + C["^reset"]
return "".join([a for a in args if a not in C])


def hide_cursor():
Expand Down Expand Up @@ -316,11 +319,12 @@ def update_worklog(
@click.option("-t", "--token", help="JIRA_TOKEN value", envvar="JIRA_TOKEN")
@click.option("-m", "--email", help="JIRA_EMAIL value", envvar="JIRA_EMAIL")
@click.option("-s", "--server", help="JIRA_SERVER value", envvar="JIRA_SERVER")
@click.option("--spin/--no-spin", help="Control the spinner", default=True)
@click.option("--spin/--no-spin", help="Control the spinner", default=True, show_default=True)
@click.option("--color/--no-color", help="Control colors", default=True, show_default=True)
@click.help_option("-h", "--help", help="Show this message and exit")
@click.version_option(help="Show the version and exit")
@click.pass_context
def cli(ctx, file, key, token, email, server, spin):
def cli(ctx, file, key, token, email, server, spin, color):
"""
Configure JIRA connection by using default config files, environment
variables, or options below. The discovery of default config files uses
Expand All @@ -341,6 +345,7 @@ def cli(ctx, file, key, token, email, server, spin):
- JIRA_PROJECT_KEY (your team's project key)
"""
global use_spinner; use_spinner = spin
global use_color; use_color = color

ctx.ensure_object(dict)
cfg = {
Expand Down
20 changes: 20 additions & 0 deletions tests/test_dzira.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import click
from click.testing import CliRunner

import src.dzira.dzira as dzira
from src.dzira.dzira import (
CONFIG_DIR_NAME,
D,
Expand Down Expand Up @@ -96,6 +97,13 @@ def test_uses_right_codes_for_given_colors(self, test_input, expected):
def test_is_variadic(self, test_input, expected):
assert c(*test_input) == expected

def test_returns_string_without_color_tags_when_use_color_is_false(self, mocker):
mocker.patch("src.dzira.dzira.use_color", False)

assert c("^bold", "this ", "^red", "text ", "^blue", "does not have colors", "^reset") == (
"this text does not have colors"
)


class TestCursorHelpers:
def test_hides_cursor(self, mocker):
Expand Down Expand Up @@ -598,6 +606,18 @@ def test_help(self):
assert result.exit_code == 0
assert "Configure JIRA connection" in result.output

def test_by_default_uses_colorful_output(self):
result = self.runner.invoke(dzira.cli, ["log", "-h"])

assert result.exit_code == 0
assert dzira.use_color

def test_supports_option_to_set_use_color(self):
result = self.runner.invoke(dzira.cli, ["--no-color", "log", "-h"])

assert result.exit_code == 0
assert dzira.use_color is False


class TestLs(CliTest):
def test_help(self):
Expand Down

0 comments on commit 6445f81

Please sign in to comment.