Class AliasManager
java.lang.Object
org.aesh.readline.alias.AliasManager
-
Constructor Summary
ConstructorsConstructorDescriptionAliasManager(File aliasFile, boolean persistAlias) Creates a new AliasManager with the specified alias file and persistence setting. -
Method Summary
Modifier and TypeMethodDescriptionReturns the usage information for the alias command.findAllMatchingNames(String name) Finds all alias names that start with the given prefix.Retrieves an alias by its name.getAliasName(String input) Expands an alias if the first word of the input matches an alias name.Returns a list of all defined alias names.parseAlias(String buffer) Parses an alias command and either creates a new alias, lists specified aliases, or returns all aliases.voidpersist()Persists all aliases to the alias file.Returns a formatted string containing all defined aliases sorted alphabetically.removeAlias(String buffer) Removes one or more aliases based on the unalias command input.Returns the usage information for the unalias command.booleanverifyNoNewAliasConflict(String aliasName) It is not allowed to create an alias if it conflicts with a command already present
-
Constructor Details
-
AliasManager
Creates a new AliasManager with the specified alias file and persistence setting. If the alias file exists, aliases are read from it during initialization.- Parameters:
aliasFile- the file to read and persist aliases from/to, may be nullpersistAlias- if true, aliases will be persisted to the alias file- Throws:
IOException- if an I/O error occurs while reading the alias file
-
-
Method Details
-
verifyNoNewAliasConflict
It is not allowed to create an alias if it conflicts with a command already present- Parameters:
aliasName- name of the alias- Returns:
- true if there is no conflict
- Throws:
AliasConflictException- if the alias name conflicts with an existing command
-
persist
public void persist()Persists all aliases to the alias file. This method writes all current aliases to the configured alias file if persistence is enabled and an alias file was specified. The aliases are sorted before writing. If the file already exists, it is deleted and recreated. -
printAllAliases
Returns a formatted string containing all defined aliases sorted alphabetically. Each alias is printed on a separate line in the format "alias name='value'".- Returns:
- a string representation of all aliases, with each alias on a separate line
-
getAlias
-
getAliasName
Expands an alias if the first word of the input matches an alias name. If a matching alias is found, returns the alias value with the remainder of the input appended.- Parameters:
input- the input string to check for alias expansion- Returns:
- an Optional containing the expanded command if an alias matches, or an empty Optional if no alias matches the first word
-
findAllMatchingNames
-
getAllNames
-
removeAlias
Removes one or more aliases based on the unalias command input. The buffer should contain the unalias command followed by one or more alias names to remove, separated by spaces.- Parameters:
buffer- the unalias command string containing alias names to remove- Returns:
- null if all aliases were successfully removed, an error message if an alias was not found, or usage information if the command is invalid
-
parseAlias
Parses an alias command and either creates a new alias, lists specified aliases, or returns all aliases.Supported formats:
- "alias" - returns all defined aliases
- "alias --help" - returns usage information
- "alias name=value" - creates or updates an alias
- "alias name1 name2" - lists the specified aliases
- Parameters:
buffer- the alias command string to parse- Returns:
- null if an alias was successfully created, a string containing alias definitions when listing, an error message if the command is invalid, or usage information
-
aliasUsage
Returns the usage information for the alias command.- Returns:
- a string containing the alias command usage syntax
-
unaliasUsage
Returns the usage information for the unalias command.- Returns:
- a string containing the unalias command usage syntax
-