def test_get_theme_not_a_link_raises(self): '''Test getting theme when the active path isn't a link.''' link_path = Path(self.link_dir.name) theme_link_path = Path(self.link_dir.name) / Path('theme.yaml') theme_link_path.touch() templater = Templater(link_path) with self.assertRaises(LinkMalformedError): templater.get_theme()
def test_get_theme_link_tgt_malformed_raises(self): '''Test getting theme from a malformed link target name.''' link_path = Path(self.link_dir.name) theme_link_path = Path(self.link_dir.name) / Path('theme.yaml') theme_tgt_path = Path(self.theme_dir.name) / Path('notyaml.txt') theme_tgt_path.touch() theme_link_path.symlink_to(theme_tgt_path) templater = Templater(link_path) with self.assertRaises(LinkMalformedError): templater.get_theme()
def _pick_theme_interactive(templater: Templater, host_cfg: hostconfig.HostConfig, flag: str) -> str: '''Picks a theme and maybe prompts based on current state.''' return flag or templater.get_theme() or click.prompt( 'Select a theme', default=host_cfg.default_theme, type=click.Choice(templater.list_themes()))
def test_get_theme(self): '''Test getting theme with a correctly formatted link.''' link_path = Path(self.link_dir.name) theme_link_path = Path(self.link_dir.name) / Path('theme.yaml') theme_tgt_path = Path(self.theme_dir.name) / Path('cooltheme.yaml') theme_tgt_path.touch() theme_link_path.symlink_to(theme_tgt_path) templater = Templater(link_path) self.assertEqual(templater.get_theme(), 'cooltheme')
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_theme_no_link_returns_none(self): '''Test getting theme with no link present.''' link_path = Path(self.link_dir.name) templater = Templater(link_path) self.assertIsNone(templater.get_theme())
def _pick_theme_noninteractive(templater: Templater, host_cfg: hostconfig.HostConfig, flag: str) -> str: '''Picks a theme without prompting.''' return flag or templater.get_theme() or host_cfg.default_theme