Added help for all commands & general better output

Changes:
- added help fo all/specific commands
- unified the output of check/update
- beautified the output of check/update
- a little code cleanup
This commit is contained in:
Neocky 2021-03-21 14:30:27 +01:00
parent 01465eb769
commit e1efcc4fc7
5 changed files with 113 additions and 28 deletions

View File

@ -1,7 +1,7 @@
import sys
from utils.consoleoutput import oColors
from utils.utilities import getHelp
from utils.utilities import getHelp, getCommandHelp
from handlers.handle_config import checkConfig
from plugin.plugin_downloader import searchPackage, getSpecificPackage
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
@ -68,6 +68,10 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
if inputCommand == 'exit':
sys.exit()
if inputCommand == 'help':
print(inputParams)
if inputSelectedObject == 'command' or inputSelectedObject == 'commands':
getCommandHelp(inputParams)
else:
getHelp()
break
if inputCommand == 'remove':
@ -77,7 +81,7 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
papermc_downloader(inputSelectedObject, inputParams)
break
else:
print(oColors.brightRed + "Command not found. Please try again." + oColors.standardWhite)
print(oColors.brightRed + "Error: Command not found. Please try again. :(" + oColors.standardWhite)
getInput()
getInput()
@ -88,7 +92,8 @@ def getInput():
inputCommand, inputSelectedObject, *inputParams = input("pluGET >> ").split()
break
except ValueError:
print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite)
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
inputParams = inputParams[0] if inputParams else None
handleInput(inputCommand, inputSelectedObject, inputParams)

View File

@ -61,7 +61,7 @@ def searchPackage(ressourceName):
url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name&sort=-downloads"
packageName = doAPIRequest(url)
i = 1
print(f"Searching: {ressourceName}")
print(oColors.brightBlack + f"Searching: {ressourceName}" + oColors.standardWhite)
print("Index | Name | Description | Downloads")
for ressource in packageName:
pName = ressource["name"]

View File

@ -85,7 +85,6 @@ def eggCrackingJar(localJarFileName):
return pluginVersion
def checkInstalledPackage(inputSelectedObject="all"):
createPluginList()
if not checkConfig().localPluginFolder:
@ -95,9 +94,10 @@ def checkInstalledPackage(inputSelectedObject="all"):
pluginList = os.listdir(checkConfig().pathToPluginFolder)
i = 0
oldPackages = 0
print(f"Checking: {inputSelectedObject}")
print("Index | Name | Installed V. | Latest V. | Update available")
print("─────────────────────────────────────────────────────────────────────────────────────")
print(oColors.brightBlack + f"Checking: {inputSelectedObject}" + oColors.standardWhite)
print("┌─────┬────────────────────────────────┬──────────────┬───────────┬───────────────────┐")
print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │")
print("└─────┴────────────────────────────────┴──────────────┴───────────┴───────────────────┘")
try:
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="cyan"):
try:
@ -131,22 +131,28 @@ def checkInstalledPackage(inputSelectedObject="all"):
if inputSelectedObject != "*" and inputSelectedObject != "all":
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if pluginLatestVersion == 'N/A':
print(oColors.darkBlack + f" [{1}]".ljust(8), end='')
else:
print(f" [{1}]".ljust(8), end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(12), end='')
print(f" {pluginIsOutdated}".ljust(5))
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite)
break
else:
if pluginLatestVersion == 'N/A':
print(oColors.darkBlack + f" [{i+1}]".ljust(8), end='')
else:
print(f" [{i+1}]".ljust(8), end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(12), end='')
print(f" {pluginIsOutdated}".ljust(5))
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite)
i += 1
except TypeError:
print(oColors.brightRed + "Aborted checking for updates." + oColors.standardWhite)
print(oColors.brightRed + "Error occured: Aborted checking for updates." + oColors.standardWhite)
print(oColors.brightYellow + f"Old packages: [{oldPackages}/{i}]" + oColors.standardWhite)
@ -160,9 +166,10 @@ def updateInstalledPackage(inputSelectedObject='all'):
i = 0
pluginsUpdated = 0
indexNumberUpdated = 0
print(f"Updating: {inputSelectedObject}")
print("Index | Name | Old V. | New V.")
print("───────────────────────────────────────────────────────────")
print(oColors.brightBlack + f"Updating: {inputSelectedObject}" + oColors.standardWhite)
print("┌─────┬────────────────────────────────┬────────────┬──────────┐")
print("│ No. │ Name │ Old V. │ New V. │")
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
try:
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="red"):
try:
@ -177,14 +184,13 @@ def updateInstalledPackage(inputSelectedObject='all'):
i += 1
continue
pluginIdStr = str(pluginId)
if pluginId == None or pluginId == '':
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
continue
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if INSTALLEDPLUGINLIST[i][3] == True:
print(f" [{indexNumberUpdated+1}]".ljust(8), end='')
print(f"{fileName}".ljust(30), end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(8), end='')
print(" ", end='')
print(f"{latestVersion}".ljust(8))
@ -233,7 +239,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
if inputSelectedObject == 'all':
if INSTALLEDPLUGINLIST[i][3] == True:
print(f" [{indexNumberUpdated+1}]".ljust(8), end='')
print(f"{fileName}".ljust(30), end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(8), end='')
print(" ", end='')
print(f"{latestVersion}".ljust(8))
@ -277,10 +283,10 @@ def updateInstalledPackage(inputSelectedObject='all'):
i = i + 1
except TypeError:
print(oColors.brightRed + "Aborted updating for plugins." + oColors.standardWhite)
print(f"[{pluginsUpdated}/{i}] Plugins updated")
print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite)
print(oColors.brightYellow + f"[{pluginsUpdated}/{i}] Plugins updated" + oColors.standardWhite)
if inputSelectedObject =='all' and pluginsUpdated == 0:
print(oColors.brightGreen + "All plugins are on the latest version!" + oColors.standardWhite)
print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite)
def getInstalledPlugin(localFileName, localFileVersion):

View File

@ -13,12 +13,11 @@ def clearConsole():
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
class oColors:
standardWhite = "\033[0m"
brightYellow = "\033[93m"
brightMagenta = "\033[95m"
brightBlack = "\033[90m"
brightRed = "\033[91m"
brightGreen = "\033[92m"
darkMagenta = "\033[35m"
brightBlack = "\033[90m"
brightYellow = "\033[93m"
brightMagenta = "\033[95m"
def printLogo():

View File

@ -12,12 +12,87 @@ from handlers.handle_sftp import createSFTPConnection
def getHelp():
print(oColors.brightYellow+ "Need help?" + oColors.standardWhite)
print("Check the docs here:")
print("For a list of all the commands: 'help command'")
print("Or check the docs here:")
print("https://github.com/Neocky/pluGET")
print("Or go to the official discord.")
print("The link for discord can also be found on Github!")
def getCommandHelp(optionalParams):
if optionalParams == None:
optionalParams = 'all'
print("┌────────────────┬─────────────────┬─────────────────┬────────────────────────────────────────────────────────┐")
print("│ Command │ Selected Object │ Optional Params │ Function │")
print("└────────────────┴─────────────────┴─────────────────┴────────────────────────────────────────────────────────┘")
while True:
if optionalParams == 'all':
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
print(" exit ./anything Exit pluGET")
print(" help ./anything Get general help")
print(" help command all/command Get specific help to the commands of pluGET")
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(" get Name/ID Version Downloads the latest version of a plugin")
print(" check Name/ID/all Check for an update of an installed plugin")
print(" update Name/ID/all Update installed plugins to the latest version")
print(" search Name Search for a plugin and download the latest version")
print(" remove Name/ID Delete an installed plugin")
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
print(" check serverjar Check installed server software for an update")
print(" update serverjar Version/Latest Update installed server software to a specific version")
print(" get-paper PaperVersion McVersion Downloads specific PaperMc version")
break
if optionalParams == 'exit':
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
print(" exit ./anything Exit pluGET")
break
if optionalParams == 'help':
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
print(" help ./anything Get general help")
print(" help command all/command Get specific help to the commands of pluGET")
break
if optionalParams == 'get':
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(print(" get Name/ID Version Downloads the latest version of a plugin"))
break
if optionalParams == 'check':
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(" check Name/ID/all Check for an update of an installed plugin")
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
print(" check serverjar Check installed server software for an update")
break
if optionalParams == 'update':
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(" update Name/ID/all Update installed plugins to the latest version")
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
print(" update serverjar Version/Latest Update installed server software to a specific version")
break
if optionalParams == 'search':
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(" search Name Search for a plugin and download the latest version")
break
if optionalParams == 'remove':
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
print(" remove Name/ID Delete an installed plugin")
break
if optionalParams == 'get-paper':
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
print(" get-paper PaperVersion McVersion Downloads specific PaperMc version")
break
else:
print(oColors.brightRed + "Error: Help for Command not found. Please try again. :(" + oColors.standardWhite)
break
def check_local_plugin_folder():
if checkConfig().localPluginFolder:
if checkConfig().seperateDownloadPath: