def test_get_color_not_a_link_raises(self): '''Test getting color when the active path isn't a link.''' link_path = Path(self.link_dir.name) color_path = Path(self.link_dir.name) / Path('color.yaml') color_path.touch() templater = Templater(link_path) with self.assertRaises(LinkMalformedError): templater.get_color()
def test_get_color_link_malformed_raises(self): '''Test getting color from a malformed link target name.''' link_path = Path(self.link_dir.name) color_link_path = Path(self.link_dir.name) / Path('color.yaml') color_tgt_path = Path(self.color_dir.name) / Path('notyaml.txt') color_tgt_path.touch() color_link_path.symlink_to(color_tgt_path) templater = Templater(link_path) with self.assertRaises(LinkMalformedError): templater.get_color()
def _pick_color_interactive(templater: Templater, host_cfg: hostconfig.HostConfig, flag: str) -> str: '''Picks a color and maybe prompts based on current state.''' return flag or templater.get_color() or click.prompt( 'Select a color', default=host_cfg.default_color, type=click.Choice(templater.list_colors()))
def test_get_color(self): '''Test getting color with a correctly formatted link.''' link_path = Path(self.link_dir.name) color_link_path = Path(self.link_dir.name) / Path('color.yaml') color_tgt_path = Path(self.color_dir.name) / Path('coolcolor.yaml') color_tgt_path.touch() color_link_path.symlink_to(color_tgt_path) templater = Templater(link_path) self.assertEqual(templater.get_color(), 'coolcolor')
def cli(ctx: click.Context): '''Modular dotfile manager. Run without a command for a summary of current state. ''' MODOT_PATH.mkdir(exist_ok=True, parents=True) if ctx.invoked_subcommand is None: host = hostconfig.get_deployed_host(ACTIVE_HOST_PATH) print(f'Deployed: {str(host)}' if host else 'No deployed host config') templater = Templater(MODOT_PATH) deployed_theme = templater.get_theme() print(f'Deployed theme: {deployed_theme}' if deployed_theme else 'No deployed theme') deployed_color = templater.get_color() print(f'Deployed color: {deployed_color}' if deployed_color else 'No deployed color') print('--help for usage')
def test_get_color_no_link_returns_none(self): '''Test getting color with no link present.''' link_path = Path(self.link_dir.name) templater = Templater(link_path) self.assertIsNone(templater.get_color())
def _pick_color_noninteractive(templater: Templater, host_cfg: hostconfig.HostConfig, flag: str) -> str: '''Picks a color without prompting.''' return flag or templater.get_color() or host_cfg.default_color