def finish(fast_forward: bool): """ Merge current feature branch into develop. """ pretend = context.get('pretend', False) if not pretend and (git.staged() or git.unstaged()): log.err("You have uncommitted changes in your repo!\n" "You need to stash them before you merge the hotfix branch") sys.exit(1) branch = git.current_branch(refresh=True) base = common.get_base_branch() prompt = "<32>Merge <33>{}<32> into <33>{}<0>?".format(branch.name, base) if not click.confirm(shell.fmt(prompt)): log.info("Cancelled") return common.assert_branch_type('task') hooks.register.call('pre-task-finish', branch, base) # Merge task into it's base feature branch common.git_checkout(base) common.git_pull(base) common.git_merge(base, branch.name, no_ff=not fast_forward) # Cleanup common.git_branch_delete(branch.name) common.git_prune() common.git_checkout(base) hooks.register.call('post-task-finish', branch, base)
def init(quick: bool, blank: bool, force: bool): """ Create an empty pelconf.yaml from template """ config_file = 'pelconf.yaml' prompt = "-- <35>{} <32>already exists. Wipe it?<0>".format(config_file) if not force and exists(config_file) and not click.confirm( shell.fmt(prompt)): log.info("Canceled") return ctx = dict(blank=blank) if not blank: form = InitForm().run(quick=quick) ctx.update(form.values) config_content = templates.Engine().render_file('pelconf.yaml', ctx) log.info('Writing <35>{}'.format(config_file)) fs.write_file(config_file, config_content) if context.get('verbose') > 0: print( f"{'- ' * 40}\n{shell.highlight(config_content, 'yaml')}{'- ' * 40}" )
def cprint(msg: str, *args: Any, **kw: Any): """ Will convert the given message to an echo statement with color opcodes. This supports the same syntax as `peltak.core.shell.fmt` (used internally here). The color processing will replace any tag like object in format ``<NUMBER>`` into a corresponding opcode. Here's a quick cheatsheet on some of the more usefull opcodes ========== ================================================================= Tag Description ---------- ----------------------------------------------------------------- ``<0>`` Reset all formatting to default values. ``<1>`` Intensify current color (will affect all other color opcodes). ``<31>`` Set text color to red. ``<32>`` Set text color to green. ``<33>`` Set text color to yellow. ``<34>`` Set text color to blue. ``<35>`` Set text color to pink. ``<35>`` Set text color to teal. ========== ================================================================= **Usage:** .. code-block:: jinja {{ '<35>hello, <32>world' | cprint }} will result in the following:: echo "\\x1b[35mhello, \\x1b[32mworld\\x1b[0m" Which inside a terminal will be rendered as *hello* in ping and world in green. **cprint** also supports formatting, same as in the built-in ``format()`` function. .. code-block:: jinja {{ "hello, {}, I'm {name}" | cprint('Susan', name='John') }} will result in:: echo "hello, Susan, I'm John\\x1b[0m" """ return shell.fmt('echo "{}<0>"', str(msg).format(*args, **kw))
def header(title: Any) -> str: """ Converts a given title into a pretty header with colors. **Usage:** .. code-block:: jinja {{ 'hello' | header }} will result in:: = hello ================================================================ The resulting string will be colored for printing in the terminal. """ title = str(title) if (len(title) > 72): title = title[0:70] + '...' remaining = 80 - len(title) - 3 return shell.fmt('echo "<32>= <35>{title} <32>{bar}<0>"', title=title, bar='=' * remaining)
def test_formatting_works(msg, args, kw, expected): assert shell.fmt(msg, *args, **kw) == expected
def test_removes_color_tags_when_not_on_tty(msg, expected): assert shell.fmt(msg) == expected
def test_properly_converts_to_shell_opcodes_when_on_tty(msg, expected): assert shell.fmt(msg) == expected
def pretty_prompt(self) -> str: """ Return a colorized prompt ready to be displayed to the user. """ return shell.fmt('<1>{}<0>'.format(self.prompt))