def __call__(self): Command.__call__(self) if self.alias and self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) if not self.alias_dict: raise errors.AliasNotDefinedError() if self.alias is None: log.logger.debug('Prompting to destroy local alias database.') prompt = 'Remove all local aliases defined in this directory? (y/n): ' y_or_n = utils.getch(prompt) if y_or_n == 'y': self.alias_dict = {} print() log.logger.info( 'Done. The local alias database has been removed.') else: print() log.logger.info('OK. Nothing has been done.') return else: self.alias_dict.pop(self.alias) log.logger.info('Removed local alias "{}".'.format(self.alias)) self.commit() if self.alias_dict: print() self.show_search() else: log.logger.debug('Removing {}.'.format( self.LOCALALIAS_DB_FILENAME)) os.remove(self.LOCALALIAS_DB_FILENAME)
def __call__(self): super().__call__() if not self.alias_dict: self.purge_db() raise errors.AliasNotDefinedError(global_=self.global_) if self.alias is None: self.show_search(prefix='') elif self.alias[-2:] == '..': self.show_search(prefix=self.alias[:-2]) elif self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) else: self.show(self.alias)
def __call__(self): super().__call__() if self.alias and self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) msg_fmt = 'Edited local alias "{}".' self.alias_dict[self.alias] = self.edit_alias() log.logger.info(msg_fmt.format(self.alias)) self.commit()
def __call__(self): super().__call__() if not self.alias_dict: raise errors.AliasNotDefinedError() if self.alias is None: self.show_search() else: self.show_search(self.alias)
def __call__(self): super().__call__() if self.alias and self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) try: self.edit_alias() log.logger.info('Edited alias: "%s".', self.alias) except errors.BlankDefinition as e: log.logger.info(str(e)) self.remove_alias() self.commit()
def __call__(self): Command.__call__(self) if self.alias and self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) if not self.alias_dict: raise errors.AliasNotDefinedError(global_=self.global_) if self.alias is None: log.logger.debug('Prompting to destroy local alias database.') prompt = 'Remove all local aliases defined in this directory? (y/n): ' y_or_n = utils.getch(prompt) if y_or_n == 'y': self.alias_dict = {} print() log.logger.info( 'Done. The local alias database has been removed.') else: return self.abort() else: self.remove_alias() self.commit()
def show_search(self, *, prefix): """Prints all aliases that start with @prefix to stdout.""" log.logger.debug('Running show command for all defined aliases.') sorted_aliases = sorted( [alias for alias in self.alias_dict if alias.startswith(prefix)], key=lambda x: x.lower()) if not sorted_aliases: raise errors.AliasNotDefinedError(alias=self.alias) for alias in sorted_aliases: if self.verbose: print() self.show(alias)
def __call__(self): super().__call__() if self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias) new_alias = self.args[0] if new_alias in self.alias_dict: y_or_n = utils.getch( '"{}" is already in use. Overwrite? (y/n): '.format(new_alias)) if y_or_n == 'y': print() else: return self.abort() self.alias_dict[new_alias] = self.alias_dict[self.alias] self.alias_dict.pop(self.alias) msg_fmt = 'Alias "{}" has successfully been renamed to "{}".' log.logger.info(msg_fmt.format(self.alias, new_alias)) self.commit()
def show_search(self, prefix=''): """Prints all aliases that start with @prefix to stdout.""" log.logger.debug('Running show command for all defined aliases.') sorted_aliases = sorted( [alias for alias in self.alias_dict if alias.startswith(prefix)]) if not sorted_aliases: raise errors.AliasNotDefinedError(alias=self.alias) short_aliases_exist = False for alias in sorted_aliases: if '\n' not in self.alias_dict[alias]: self.show(alias) short_aliases_exist = True for i, alias in enumerate(sorted_aliases): if '\n' in self.alias_dict[alias]: if i > 0 or short_aliases_exist: print() self.show(alias)
def __call__(self): super().__call__() if self.alias not in self.alias_dict: raise errors.AliasNotDefinedError(alias=self.alias, returncode=127) self.execute()