Method and device for executing command in command line tool, equipment and medium
By configuring command dependency file information using a preset configuration file in the command-line tool, the risks of administrator privileges and scalability issues during the download process are resolved, thereby improving security and scalability.
Patent Information
- Application Number
- CN202410718178.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2025-12-05
AI Technical Summary
Existing command-line tools require administrator privileges to download during application development, which increases the risk of core system data being tampered with, and the commands are fixed and not easily expandable.
By configuring the configuration information of the files that the command depends on in the command-line tool through a preset configuration file, querying the file identifier based on the target command identifier, and downloading the file to be downloaded from the server, the cloud configuration and on-demand loading of the target command are realized, reducing the dependence on administrator privileges.
It reduces the risk of core system data being tampered with, improves security, and enhances the extensibility of command-line tools by extending preset configuration files.
Smart Images

Figure CN121070451A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to computer technology, and more particularly to a method, apparatus, device, and medium for executing commands in a command-line tool. Background Technology
[0002] Command-line interfaces (CLIs) are programs that allow you to operate a computer by entering commands in a command-line interface. They provide command interfaces and functions for tasks such as file management and code modification.
[0003] Currently, application development may require downloading numerous command-line tools to meet specific needs. Since installing these tools requires administrator privileges (i.e., root privileges), this increases the risk of core system data being tampered with. Furthermore, using multiple command-line tools for application development results in relatively fixed commands within each tool, making them difficult to extend. Summary of the Invention
[0004] This disclosure provides a method, apparatus, device, and medium for executing commands in a command-line tool, which can reduce the risk of core system data being tampered with, improve security, and ensure the scalability of the command-line tool.
[0005] In a first aspect, embodiments of this disclosure provide a method for executing commands in a command-line tool, applied to a terminal, including:
[0006] Obtain the target command identifier in the command line interface, wherein the command line interface is the interactive interface of the command line tool, and the command line tool includes a preset configuration file, which contains configuration information of the files on which the command execution in the command line tool depends;
[0007] Obtain the file identifier of the downloaded file corresponding to the target command identifier;
[0008] Based on the file identifier, query the target file identifier corresponding to the target command identifier in the configuration information to determine the file identifier of the file to be downloaded;
[0009] Download the file to be downloaded from the server according to the file identifier of the file to be downloaded, and execute the target command in combination with the file to be downloaded corresponding to the target command identifier and the downloaded file.
[0010] Secondly, embodiments of this disclosure also provide a command execution device for a command-line tool, applied to a terminal, the device comprising:
[0011] The command identification obtaining module is configured to obtain a target command identification in a command line interface, wherein the command line interface is an interactive interface of the command line tool, and the command line tool comprises a preset configuration file, and the preset configuration file contains configuration information of files relied on by command execution in the command line tool.
[0012] The file identification obtaining module is configured to obtain a file identification of a downloaded file corresponding to the target command identification.
[0013] The downloaded file determining module is configured to query a target file identification corresponding to the target command identification in the configuration information according to the file identification, and determine a file identification of a to-be-downloaded file.
[0014] The command executing module is configured to download the to-be-downloaded file from a server according to the file identification of the to-be-downloaded file, and execute a target command in combination with the to-be-downloaded file and the downloaded file corresponding to the target command identification.
[0015] In a third aspect, the embodiments of the present disclosure further provide an electronic device, which comprises:
[0016] one or more processors;
[0017] a storage device configured to store one or more programs,
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the command execution method in the command line tool according to any embodiment of the present disclosure.
[0019] In a fourth aspect, the embodiments of the present disclosure further provide a storage medium containing computer executable instructions, which are used to execute the command execution method in the command line tool according to any embodiment of the present disclosure when executed by a computer processor.
[0020] The embodiments of the present disclosure provide a command execution method in a command line tool, which configures configuration information of files relied on by command execution in the command line tool through a preset configuration file. Based on a file identification of a downloaded file corresponding to a target command identification, a target file identification corresponding to the target command identification in the configuration information is queried to obtain a file identification of a to-be-downloaded file. Then, the to-be-downloaded file is downloaded from a server according to the file identification of the to-be-downloaded file, and cloud configuration of a target command is realized and loaded on demand. Since downloading and installation of the to-be-downloaded file do not require administrator permissions, the risk of tampering with system core data is reduced, and security is improved. In addition, since the preset configuration file configures configuration information of files relied on by command execution in the command line tool, the command line tool can be extended by modifying the configuration information of the preset configuration file, and the extensibility of the command line tool is improved. BRIEF DESCRIPTION OF DRAWINGS
[0021] The above and other features, aspects and advantages of embodiments of the present disclosure will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings. Like or similar elements and / or features throughout the drawings are denoted by the same or similar reference numerals. It should be understood that the drawings are schematic and elements and / or features not be necessarily to scale.
[0022] Figure 1 A flowchart of a method for executing a command in a command line tool according to an embodiment of the present disclosure;
[0023] Figure 2 A flowchart of a method for executing a command in a command line tool according to another embodiment of the present disclosure;
[0024] Figure 3 A flowchart of a method for executing a command in a command line tool according to still another embodiment of the present disclosure;
[0025] Figure 4 A structural diagram of an apparatus for executing a command in a command line tool according to an embodiment of the present disclosure;
[0026] Figure 5 A structural diagram of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] Embodiments of the present disclosure will be described more fully hereinafter with reference to the accompanying drawings. While several embodiments of the present disclosure are shown in the drawings, it is understood that the present disclosure can be embodied in various forms and should not be construed as being limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and fully convey the scope of the present disclosure to those skilled in the art. It should be understood that the drawings and embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure.
[0028] It should be understood that the various steps of the method embodiments of the present disclosure can be performed in different orders and / or in parallel. In addition, the method embodiments can include additional steps and / or omit performing the steps shown. The scope of the present disclosure is not limited in this regard.
[0029] The term "comprising" and variations thereof as used herein are used inclusively, i.e., "comprising but not limited to." The term "based on" is "based at least in part on." The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments." Related terms are defined in the description that follows.
[0030] It should be noted that the terms "first", "second", and the like mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not intended to limit the order or interdependence of the functions performed by these devices, modules or units.
[0031] It should be noted that the terms "one", "multiple" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise explicitly indicated in the context, it should be understood as "one or more".
[0032] The names of the messages or information exchanged between the plurality of devices in the embodiments of the present disclosure are only for illustrative purposes, and are not intended to limit the scope of the messages or information.
[0033] Figure 1 A flowchart of an execution method of a command in a command line tool provided by an embodiment of the present disclosure, the embodiment of the present disclosure is applicable to separate the general code and configuration file of the command in the command line tool, and the implementation program of the built-in root command in the command line tool, but no longer contains the files relied on by the subcommand running. The general code of the command and the configuration information of the files relied on by the configuration command running are configured on the server side. A command line tool is installed in an electronic device, and the on-demand loading of the command is realized according to the configuration file. The method can be executed by an execution device of the command in the command line tool, and the device can be realized in the form of software and / or hardware. Optionally, the electronic device is realized by an electronic device, which can be a mobile terminal or a PC terminal.
[0034] As shown in Figure 1 The method comprises:
[0035] S110, obtaining a target command identifier in a command line interface.
[0036] The command line tool is an indispensable tool for developers to perform application development and system management and the like. The command line interface is an interactive interface of the command line tool. The command line tool interacts with the user in the form of the command line interface. The operating system calls the corresponding command according to the command and parameter input by the user in the command line interface, and executes the command based on the files relied on by the command.
[0037] The command line tool includes a preset configuration file containing configuration information of files relied on by a command in the command line tool. It should be noted that the implementation program of the root command built in the command line tool is used to enter the command line tool, and does not contain files relied on by a subcommand, but records configuration information of files relied on by a command through a preset dependent file. If a target command is to be run, the configuration information can be queried according to the target command identifier to obtain a file to be downloaded, thereby realizing on-demand downloading of the command and reducing the data amount of the command line tool.
[0038] The target command represents a subcommand input in the command line interface. The target command identifier is used to represent the target command. The subcommand can represent a command configured through the preset configuration file. The implementation program of only the root command is built in the command line tool, which can shorten the downloading and installation time of the command line tool. The root command can represent an entry of the command line tool, for example, the character corresponding to the root command can be the name of the command line tool itself. For example, the command line tool is started by inputting the root command in the command line interface. When a subcommand is input in the command line interface, the character corresponding to the root command needs to be added before the character corresponding to the subcommand. The subcommand represents a command declared through the preset configuration file. The implementation program of the subcommand is configured on the server, and the configuration information of files relied on by the subcommand is declared through the preset configuration file. When the subcommand is needed, the files relied on by the subcommand are downloaded and installed from the server, thereby realizing on-demand loading and installation of the subcommand.
[0039] Optionally, the type of an application program engine used for parsing and executing the subcommand is configured through a description field corresponding to the subcommand in the preset configuration file. The application program engine can represent a virtual machine for processing a command, which is usually attached in a web browser.
[0040] Optionally, the preset configuration file further has built-in templates and code snippets required for development, wherein the templates include a template for developing a subcommand and a template for developing a template. In order to be compatible with the original template, for example, an official template of a set command, the original template can be registered to the preset configuration file in a set format. For example, the creat command is a template display command, and the built-in template and the registered template can be associated with the creat command.
[0041] Optionally, before the target command identifier in the command line interface is obtained, the following steps are further included:
[0042] A version query request of the command line tool is sent to the server, and version information of the command line tool returned by the server is obtained. If it is determined according to the version information that the command line tool meets a preset version update condition, a version-updated command line tool is downloaded, and the version-updated command line tool is installed.
[0043] For example, after a root command is input in a command line interface, a command line tool is started. A preset welcome statement and a command prompt information are displayed in the command line interface. And the latest version information of the command line tool is obtained from a server. The newly obtained version information is compared with the locally stored version information of the command line tool to determine whether the command line tool meets a preset version update condition. If the version information is consistent, it is determined that the command line tool does not need to be updated. After the command line tool is installed, the configuration information of the sub-commands in a preset configuration file is obtained when the root command is executed, and the name and description information of the sub-commands are displayed in the command line interface to guide the user to use the commonly used sub-commands of the command line tool.
[0044] If the server has a new version of the command line tool, it is determined that the command line tool meets the preset version update condition, the command line tool is downloaded, the locally installed command line tool is uninstalled, and then the newly downloaded command line tool is installed to update the local command line tool according to the version updated command line tool. It should be noted that the installation of the command line tool requires administrator privileges, but the present disclosure only installs one command line tool, avoiding the problem of fragmentation and system risk accumulation caused by the installation of multiple command line tools. In addition, the command line tool can automatically perceive the version upgrade and download the updated program code, avoiding the problem caused by the delay of upgrade.
[0045] After the version upgrade of the command line tool is completed, the root command and parameters input by the user in the command line interface before the version execution are obtained, and the updated command line tool is installed. After the installation is completed, the configuration information of the sub-commands in the preset configuration file is obtained when the root command is executed, and the name and description information of the sub-commands are displayed in the command line interface to guide the user to use the commonly used sub-commands and newly added sub-commands of the command line tool. Displaying the sub-commands after installing the new version of the command line tool can avoid the problem that the user does not know how to use the newly added sub-commands.
[0046] For example, the target command identifier in the command line interface is obtained by: obtaining a command character input in the command line interface; and if the command character meets a preset naming condition, determining the target command identifier according to the command character.
[0047] The preset naming condition represents a naming rule of the sub-commands. For example, the preset naming condition can specify the characters and reserved words used for naming the sub-commands. The reserved words are characters reserved in advance for subsequent construction of new sub-commands, and a sub-command composed of the reserved words is called a built-in command. For example, the reserved words are determined in advance and written into a kernel file of the command line tool. If a built-in command is created based on the reserved words subsequently, the configuration information corresponding to the built-in command is added to a preset configuration file. The occupied reserved words are deleted from the kernel file of the command line tool, and the version of the command line tool is republished.
[0048] Optionally, determining the target command identifier according to the command character can include matching the command character with a command character in a preset configuration file to determine the target command identifier. Specifically, the command character input in the command line interface is obtained, and a command execution event corresponding to the command character is triggered. Triggering the command execution event can be understood as starting an independent thread for executing the command corresponding to the command character. If the command character is a reserved word, the corresponding command execution event is exited, and it is prompted that the current command character is a reserved word. If the command character represents a built-in command, the built-in command is executed. If the command character is neither a reserved word nor a built-in command, the command character is matched with a command identifier configured in the preset configuration file. If the command character is a command configured in the preset configuration file, the command matched successfully is taken as the target command. If the command character is not a command configured in the preset configuration file, the corresponding command execution event is exited, and it is prompted that the current command character is incorrect.
[0049] S120, obtaining a file identifier of a downloaded file corresponding to the target command identifier.
[0050] Exemplarily, a storage path corresponding to the target command is queried according to the target command identifier, where the storage path is used to store a file relied on by the target command. If there is no storage path corresponding to the target command, it is determined that the file corresponding to the target command identifier has not been downloaded. If there is a storage path corresponding to the target command, a file identifier of a downloaded file corresponding to the target command identifier is obtained according to the storage path.
[0051] If the file corresponding to the target command identifier is downloaded, the terminal stores the file in the storage path corresponding to the target command, and the file identifier of the downloaded file corresponding to the target command identifier can be obtained according to the storage path.
[0052] For example, a downloaded file corresponding to a command a is stored in a storage path yy / a / xx of a storage area, and the storage path corresponding to the command a is queried according to the command identifier of the command a. If there is no storage path corresponding to the command a, it is determined that the file relied on by the command a has not been downloaded. The configuration information in the preset configuration file can be queried according to the identifier of the command a to obtain the identifier of the file relied on by the command a as the file identifier of the to-be-downloaded file. If there is a storage path corresponding to the command a, the identifier of the file under the storage path is obtained as the file identifier of the downloaded file of the command a. Then, the file identifier of the to-be-downloaded file is determined according to the file identifier of the downloaded file of the command a.
[0053] S130, querying a target file identifier corresponding to the target command identifier in the configuration information according to the file identifier to determine the file identifier of the to-be-downloaded file.
[0054] In the embodiments of the present disclosure, the configuration information of the sub-commands is configured in the preset configuration file. For example, the configuration information configured in the preset configuration file includes a sub-command identifier (used for uniquely identifying a sub-command), version information of the sub-command, an application program engine adopted for executing the sub-command, and dependency declaration information, etc. The dependency declaration information includes a dependency and a dependency version, etc. The dependency is information describing a dependency file. The dependency file can be downloaded based on the dependency.
[0055] The dependency file can be used to carry program information relied on by an execution target command, and program information relied on by a dependency of the target command, etc. For example, it is configured in the preset configuration file that a dependency of a target command a is A, after downloading a file corresponding to A, it is found that A further relies on B and C, and then an iterative downloading operation of files corresponding to B and C is performed.
[0056] For example, if a file corresponding to the target command identifier has not been downloaded, a target file identifier corresponding to the target command identifier in the configuration information is taken as a file identifier of a file to be downloaded.
[0057] Optionally, if a file corresponding to the target command identifier has been downloaded, it is determined according to the configuration information that there is an updated version of the downloaded file, and a file identifier of a file to be downloaded is determined according to a text identifier of the file with the updated version.
[0058] For example, if a command line tool does not install a file relied on by a target command, a target file identifier corresponding to a target command identifier in configuration information included in a preset configuration file is taken as a file identifier of a file to be downloaded. If the command line tool has installed the file relied on by the target command, version information of the installed file is obtained, and version information of the target command and version information of a dependency file are read from the configuration information included in the preset configuration file. According to the version information, a version upgrade state of the target command or the dependency file of the target command is determined. The version upgrade state includes to be upgraded and not to be upgraded. If the version upgrade state is to be upgraded, a file identifier of a file to be upgraded corresponding to the target command is taken as the file identifier of the file to be downloaded.
[0059] If the file relied on by the target command has not been installed, the configuration information included in the preset configuration file is traversed to obtain a sub-command identifier and dependency declaration information. According to the sub-command identifier, a command installation file is downloaded from a server. The dependency in the dependency declaration information is obtained, and then a file relied on by the target command is downloaded from the server according to the dependency. If the execution of the file relied on by the target command further relies on other files, the other files are downloaded. The same way is used to recursively find and download the dependency files.
[0060] If the files relied on by the target command have been installed, and the command installation file has version updates but the dependent files have no version updates, the command installation file is downloaded from the server. If the files relied on by the target command have been installed, and both the command installation file and the dependent files have version updates, the command installation file and the version-updated dependent files are downloaded from the server. If the files relied on by the target command have been installed, and the dependent files have version updates, the version-updated dependent files are downloaded from the server. The downloading manner of the dependent files has been described in the embodiment of the target command not installed, and will not be repeated here.
[0061] S140, downloading the to-be-downloaded file from the server according to the file identifier of the to-be-downloaded file, and executing the target command on the corresponding to-be-downloaded file and the downloaded file according to the target command identifier.
[0062] Since the implementation program of the target command is not built in the command line tool, if the target command is to be executed, the target command needs to be loaded and installed through the command line tool. The execution of the target command relies on other dependent files, and therefore, the dependent files also need to be downloaded and installed.
[0063] Exemplarily, the to-be-downloaded file is downloaded from the server according to the file identifier of the to-be-downloaded file, and the to-be-downloaded file is stored in the target storage path and installed. The target parameters corresponding to the target command are obtained, the target command includes a target command identifier and target parameters, and the target parameters are parameters required for running the target command; and the target command is executed based on the to-be-downloaded file, the downloaded file and the target parameters.
[0064] Since the target command has been input in the command line interface before the newly downloaded file is installed, after the file is installed, the target parameters corresponding to the target command input in the command line interface are transparently transmitted to the implementation program corresponding to the target command, so as to execute the target command based on the to-be-downloaded file, the downloaded file and the target parameters.
[0065] Optionally, if the files relied on by the target command have been installed in the command line tool, and neither the target command nor the files relied thereon have version upgrades, after the target command is input in the command line interface, the target command is executed based on the installed files relied on by the target command and the target parameters.
[0066] The technical scheme of the embodiments of the present disclosure is that the preset configuration file is configured to configure the configuration information of the file relied on by the command in the command line tool. The file identifier of the to-be-downloaded file is obtained by querying the target file identifier corresponding to the target command identifier in the configuration information based on the file identifier of the corresponding downloaded file corresponding to the target command identifier. Then, the to-be-downloaded file is downloaded from the server according to the file identifier of the to-be-downloaded file, so as to realize the cloud configuration of the target command and on-demand loading. Since the downloading and installation of the to-be-downloaded file do not require administrator permission, the risk of tampering of system core data is reduced, and the security is improved. In addition, since the preset configuration file is configured to configure the configuration information of the file relied on by the command in the command line tool, the configuration information of the preset configuration file can be modified to extend the command in the command line tool, and the extensibility of the command line tool is improved.
[0067] Figure 2 For another flowchart of the execution method of the command in the command line tool provided by the embodiments of the present disclosure, the embodiments of the present disclosure are based on the above-mentioned embodiments, and the file identifier of the to-be-downloaded file is specifically limited according to the target file identifier corresponding to the target command identifier in the configuration information queried according to the file identifier. As shown in the following Figure 2 The method comprises the following steps:
[0068] S200, obtaining a target command identifier in a command line interface.
[0069] S210, querying a storage path corresponding to the target command according to the target command identifier, wherein the storage path is used to store a file relied on by the target command.
[0070] S220, if there is no storage path corresponding to the target command, it is determined that the file corresponding to the target command identifier has not been downloaded.
[0071] Since the file relied on by the command is downloaded, the terminal stores the downloaded file in the file system. The local file system is queried to determine whether the storage path corresponding to the target command exists. If the storage path corresponding to the target command is not included, it is determined that the command line tool does not install the target command, that is, the file corresponding to the target command identifier has not been downloaded.
[0072] Optionally, the command line tool traverses the list of installed commands, and if the target command is not included in the list of installed commands, it is determined that the command line tool does not install the target command, that is, the file corresponding to the target command identifier has not been downloaded.
[0073] S230, if the file corresponding to the target command identifier has not been downloaded, the target file identifier corresponding to the target command identifier in the configuration information is taken as the file identifier of the to-be-downloaded file.
[0074] If the file corresponding to the target command identifier is not downloaded, the target file identifier corresponding to the target command identifier in the configuration information included in the preset configuration file is taken as the file identifier of the file to be downloaded.
[0075] In S240, if the storage path corresponding to the target command exists, the file identifier of the downloaded file corresponding to the target command identifier is obtained according to the storage path.
[0076] If the file relied on by the target command is downloaded and installed, the file identifier of the downloaded file corresponding to the target command identifier can be obtained based on the storage path.
[0077] In S250, the storage time of the downloaded file corresponding to the target command identifier is obtained according to the file identifier of the downloaded file.
[0078] The storage time represents the existence time of the downloaded file in the storage area. In some embodiments, the storage time of the downloaded file can be recorded from the writing time of the downloaded file. The downloaded file includes the command installation file and / or the dependent file.
[0079] For example, the storage time can be determined based on the writing time of the downloaded file corresponding to the target command identifier. The storage time can be stored in the memory, the local file directory and the server respectively.
[0080] Optionally, the storage time of the downloaded file corresponding to the target command can be read from the memory first. If the storage time of the downloaded file in the memory is invalid or does not exist, the storage time of the downloaded file can be read from the local file directory. If the storage time of the downloaded file in the local file directory is also invalid or does not exist, the storage time of the downloaded file can also be obtained from the server.
[0081] In S260, if the storage time exceeds a preset update detection threshold, the preset configuration file is downloaded from the server.
[0082] The preset update detection threshold is used to trigger the terminal to perform the configuration file version update detection. For example, the preset update detection threshold is set according to the file version upgrade query period of the command line tool. If the storage time is less than or equal to the preset update detection threshold, the target command is executed based on the downloaded and installed file by default. If the storage time is greater than the preset update detection threshold, the preset configuration file needs to be downloaded again to check whether the file relied on by the target command has a file version upgrade. Since the configuration information of the target command is configured by the preset configuration file of the server, if the version of the file relied on by the target command is upgraded, the developer will update the file version information to the preset configuration file. Therefore, by downloading the preset configuration file again, it can be determined whether there is a file version upgrade.
[0083] S270, determining file version information corresponding to the target command identifier according to the newly acquired preset configuration file, and determining a to-be-updated file in the downloaded file corresponding to the target command identifier according to the text version information.
[0084] For example, a first file version number of a command installation file corresponding to the target command in the newly acquired preset configuration file is read, and a first original version number of the command installation file of the installed target command is acquired. If the read first file version number is higher than the first original version number, the command installation file corresponding to the target command is taken as the to-be-updated file. If the read first file version number is equal to the first original version number, a second file version number of a dependent file corresponding to the target command in the newly acquired preset configuration file is read, and a second original version number of the dependent file of the installed target command is acquired. If the read second file version number is higher than the second original version number, the dependent file corresponding to the target command is taken as the to-be-updated file.
[0085] Optionally, a file on which the target command depends is read from the newly acquired preset configuration file, the installed file corresponding to the target command identifier is matched with the file corresponding to the target command in the configuration information, a new file is obtained, and the identifier of the new file is taken as the file identifier of the to-be-downloaded file. For example, if a dependent file corresponding to the target command is added and the dependent file is not included in the previously downloaded file of the terminal, the identifier of the newly added file is taken as the file identifier of the to-be-downloaded file.
[0086] S280, determining the file identifier of the to-be-downloaded file according to the file identifier of the to-be-updated file.
[0087] S290, downloading the to-be-downloaded file from the server according to the file identifier of the to-be-downloaded file, and executing the target command in combination with the to-be-downloaded file corresponding to the target command identifier and the downloaded file.
[0088] For example, a file download request is sent to the server according to the file identifier of the to-be-downloaded file, and the to-be-downloaded file sent by the server is acquired, wherein the to-be-downloaded file includes the command installation file and / or the dependent file. After the command installation file and / or the dependent file are written into a preset storage area, the storage time of the target command in the memory, the local file directory and the server is updated according to the writing time of the command installation file and / or the dependent file.
[0089] If the downloading operation of the to-be-downloaded file corresponding to the target command identifier is completed, the newly downloaded file is installed. A target parameter corresponding to the target command is acquired. The target command is executed based on the to-be-downloaded file, the downloaded file and the target parameter.
[0090] Optionally, after the target command is executed on the corresponding to-be-downloaded file and the downloaded file according to the identification of the target command, the method further includes: generating a command execution record according to an execution time and an execution frequency of the target command; and when a record reporting condition is met, sending the command execution record and the user identifier to the server, so that the server generates a command analysis result based on the command execution record and the user identifier. Through the embodiment of the present disclosure, the auxiliary thread can be started to record the execution frequency and the execution time of the target command and the like, and then the command execution record can be generated according to the execution time and the execution frequency, and the command execution record can be reported to the server regularly. The server can analyze the running condition of the target command based on the command execution record and the user identifier, and obtain the command analysis result. Furthermore, the analysis report can be generated according to the command analysis result.
[0091] The technical scheme of the embodiment of the present disclosure can not perform version upgrade detection every time the target command is executed, but can determine whether the storage time corresponding to the target command exceeds a preset update detection threshold, and in the case where the storage time exceeds the preset update detection threshold, the preset configuration file is downloaded again, and the version upgrade detection is performed on the target command based on the file version information corresponding to the target command in the configuration information included in the newly downloaded preset configuration file. Through the scheme of the embodiment of the present disclosure, the execution efficiency and the automatic version upgrade can be considered, and the problem of slow running caused by the version upgrade detection every time the target command is executed can be improved.
[0092] In some embodiments, an exemplary execution manner of a command in a command line tool is as shown in Figure 3 Figure 3 This is another flowchart of an execution method of a command in a command line tool provided by the embodiment of the present disclosure.
[0093] S301, entering the command line tool.
[0094] Exemplarily, a root command is input in a command line window to enter the command line tool.
[0095] S302, determining whether there is a new version, if yes, performing S303, otherwise performing S304.
[0096] S303, downloading and installing the new version of the command line tool, and entering the command line tool.
[0097] Exemplarily, after the installation, the root command and the parameters are transmitted, and the root command is executed again to enter the command line tool.
[0098] S304, obtaining the preset configuration file of the server.
[0099] S305, obtaining the command character in the command line interface.
[0100] S306, judging whether the command character is a reserved word, if yes, executing S307, otherwise, executing S308.
[0101] S307, exiting.
[0102] S308, judging whether the command character is a subcommand, if no, executing S309, otherwise, executing S311.
[0103] S309, judging whether the command character is a built-in command, if yes, executing S310, otherwise, executing S307.
[0104] S310, executing the built-in command.
[0105] S311, judging whether the subcommand has been installed, if yes, executing S312, otherwise, executing S313.
[0106] S312, judging whether the subcommand has an update, if yes, executing S313, otherwise, executing S314.
[0107] S313, installing the command installation file of the subcommand.
[0108] For example, downloading the command security file of the new version of the subcommand, uninstalling the local subcommand, and installing the command installation file of the new version of the subcommand.
[0109] S314, judging whether the dependent file of the subcommand has an update, if yes, executing S315, otherwise, executing S316.
[0110] S315, installing the dependent file of the subcommand.
[0111] S316, executing the subcommand.
[0112] Figure 4 A command execution device structure of a command line tool provided by the embodiment of the present disclosure, which can be implemented in the form of software and / or hardware, and can be implemented by an electronic device, such as a mobile terminal or a PC.
[0113] As shown in Figure 4 , the device comprises a command identification acquisition module 410, a file identification acquisition module 420, a download file determination module 430, and a command execution module 440.
[0114] The command identification acquisition module 410 is configured to acquire a target command identification in a command line interface, wherein the command line interface is an interactive interface of the command line tool, and the command line tool comprises a preset configuration file containing configuration information of files on which a command in the command line tool depends.
[0115] The file identifier obtaining module 420 is configured to obtain a file identifier of a downloaded file corresponding to the target command identifier;
[0116] The downloaded file determining module 430 is configured to query a target file identifier corresponding to the target command identifier in the configuration information according to the file identifier, and determine a file identifier of a to-be-downloaded file;
[0117] The command executing module 440 is configured to download the to-be-downloaded file from the server according to the file identifier of the to-be-downloaded file, and execute a target command in combination with the to-be-downloaded file corresponding to the target command identifier and the downloaded file.
[0118] Optionally, the apparatus further comprises a tool version updating module, configured to:
[0119] Before obtaining the target command identifier in the command line interface, send a version query request of a command line tool to the server, and obtain version information of the command line tool returned by the server;
[0120] If it is determined according to the version information that the command line tool meets a preset version updating condition, download a version-updated command line tool;
[0121] Install the version-updated command line tool.
[0122] Optionally, the command identifier obtaining module 410 is specifically configured to:
[0123] Obtain a command character input in the command line interface;
[0124] If the command character meets a preset naming condition, determine a target command identifier according to the command character.
[0125] Optionally, the file identifier obtaining module 420 is specifically configured to:
[0126] Query a storage path corresponding to the target command according to the target command identifier, wherein the storage path is used to store a file on which the target command depends;
[0127] If there is no storage path corresponding to the target command, it is determined that a file corresponding to the target command identifier has not been downloaded;
[0128] If there is a storage path corresponding to the target command, obtain a file identifier of a downloaded file corresponding to the target command identifier according to the storage path.
[0129] Optionally, the downloaded file determining module 430 is specifically configured to:
[0130] If the file corresponding to the target command identifier has not been downloaded, a target file identifier corresponding to the target command identifier in the configuration information is taken as a file identifier of a file to be downloaded.
[0131] Optionally, the downloading file determination module 430 is specifically configured to:
[0132] If the file corresponding to the target command identifier has been downloaded, a storage time of the downloaded file corresponding to the target command identifier is obtained.
[0133] If the storage time exceeds a preset update detection threshold, the preset configuration file is downloaded from the server.
[0134] According to the newly obtained preset configuration file, file version information corresponding to the target command identifier is determined, and according to the text version information, a file to be updated in the downloaded file corresponding to the target command identifier is determined.
[0135] According to the file identifier of the file to be updated, a file identifier of a file to be downloaded is determined.
[0136] Optionally, the command execution module 440 is specifically configured to:
[0137] A target parameter corresponding to a target command is obtained, wherein the target command includes a target command identifier and a target parameter, and the target parameter is a parameter required for running the target command.
[0138] The target command is executed based on the file to be downloaded, the downloaded file, and the target parameter.
[0139] Optionally, the apparatus further includes an analysis module configured to:
[0140] After the target command is executed in combination with the file to be downloaded and the downloaded file corresponding to the target command identifier, a command execution record is generated according to an execution time and an execution frequency of the target command.
[0141] When a record reporting condition is met, the command execution record and a user identifier are sent to the server, so that a command analysis result is generated by the server based on the command execution record and the user identifier.
[0142] The command execution apparatus in the command line tool provided in the embodiments of the present disclosure can execute the command execution method in the command line tool provided in any of the embodiments of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0143] It is noted that the units and modules included in the above apparatus are only divided according to function logic, and are not limited to the above division, as long as the corresponding functions can be implemented; in addition, the specific names of each functional unit are only for easy mutual distinction, and do not serve to limit the protection scope of the embodiments of the present disclosure.
[0144] Figure 5 A structural schematic diagram of an electronic device provided by the embodiments of the present disclosure is shown. The following refers to Figure 5 which shows a structural schematic diagram of an electronic device (for example Figure 5 , a terminal device or a server) 500 suitable for implementing the embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure can include, but is not limited to, mobile terminals such as mobile phones, notebook computers, PDAs (personal digital assistants), PADs (tablets), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 5 The electronic device shown is only an example, and should not bring any limitation to the functions and use range of the embodiments of the present disclosure.
[0145] As shown in Figure 5 , the electronic device 500 can include a processing apparatus (for example, a central processor, a graphics processor, and the like) 501, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 502 or programs loaded from a storage apparatus 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing apparatus 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An edit / output (I / O) interface 505 is also connected to the bus 504.
[0146] Generally, the following apparatuses can be connected to the I / O interface 505: input apparatuses 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, and the like; output apparatuses 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, and the like; storage apparatuses 508 including, for example, a magnetic tape, a hard disk, and the like; and communication apparatuses 509. The communication apparatuses 509 can allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 with various apparatuses is shown, but it is understood that it is not required to implement or have all the apparatuses shown. More or fewer apparatuses can be alternatively implemented or possessed.
[0147] In particular, according to embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for executing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network by the communication apparatus 509, or installed from the storage apparatus 508, or installed from the ROM 502. When the computer program is executed by the processing apparatus 501, the above-mentioned functions defined in the methods of the embodiments of the present disclosure are executed.
[0148] The names of the messages or information exchanged between the plurality of devices in the embodiments of the present disclosure are only for illustrative purposes, and are not intended to limit the scope of the messages or information.
[0149] The electronic device provided by the embodiments of the present disclosure and the execution method of the command in the command line tool provided by the above-mentioned embodiments belong to the same inventive concept, and the technical details not described in the present embodiment can be referred to the above-mentioned embodiments, and the present embodiment has the same beneficial effects as the above-mentioned embodiments.
[0150] The embodiments of the present disclosure provide a computer storage medium, which stores a computer program, and the program is executed by a processor to implement the execution method of the command in the command line tool provided by the above-mentioned embodiments.
[0151] It should be noted that the computer-readable medium described above can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium, for example, can be, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any suitable combination of the foregoing. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program used or used in conjunction with an instruction execution system, apparatus or device. In the disclosure, the computer-readable signal medium can include a data signal carried in a baseband or as a part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to an electromagnetic signal, an optical signal or any suitable combination of the foregoing. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained in the computer-readable medium can be transmitted by any suitable medium, including but not limited to a wire, a cable, a RF (radio frequency) or the like, or any suitable combination of the foregoing.
[0152] In some embodiments, the client, server can communicate using any currently known or future developed network protocol, such as HTTP (HyperText Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), the Internet, and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed networks.
[0153] The computer-readable medium described above can be included in the electronic device described above; or can exist separately from the electronic device and not be assembled into the electronic device.
[0154] The computer-readable medium described above carries one or more programs, when the one or more programs are executed by the electronic device, the electronic device:
[0155] Obtaining a target command identifier in a command line interface, wherein the command line interface is an interactive interface of the command line tool, the command line tool comprises a preset configuration file, and the preset configuration file contains configuration information of files relied on by command execution in the command line tool;
[0156] Obtaining a file identifier of a downloaded file corresponding to the target command identifier;
[0157] Querying the target file identifier corresponding to the target command identifier in the configuration information according to the file identifier, to determine a file identifier of a to-be-downloaded file;
[0158] Downloading the to-be-downloaded file from a server according to the file identifier of the to-be-downloaded file, and executing a target command in combination with the to-be-downloaded file and the downloaded file corresponding to the target command identifier.
[0159] Computer program code for carrying out operations of the present disclosure can be written in one or more programming languages or combinations of languages including object or visual programming languages such as Java, Smalltalk, C++ or conventional procedural programming languages such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0160] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowcharts or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks noted in succession can in fact be executed substantially concurrently or in the reverse order, depending on the functionality involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by dedicated hardware-based systems that perform the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0161] The units described in the embodiments of the present disclosure can be implemented by means of software, or by hardware. In some cases, the name of the unit does not constitute a limitation on the unit itself.
[0162] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, and without limitation, illustrative types of hardware logic components that can be used include Field-programmable Gate Arrays (FPGAs), Application-specific Integrated Circuits (ASICs), Application-specific Standard Products (ASSPs), System-on-a-chip systems (SOCs), Complex Programmable Logic Devices (CPLDs), etc.
[0163] In the context of the present disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of a program of a processor, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0164] The above description is merely exemplary of preferred embodiments of the present disclosure and of the application of the principles of the present disclosure. It is therefore not intended to limit the scope of the disclosure to the specific implementations described and as such, the scope of the disclosure is to be defined by the claims as set forth below. The description of the disclosure is merely exemplary of the principles of the disclosure and the application of the principles of the present disclosure. It is therefore intended that the scope of the disclosure be determined solely by the claims set forth below.
[0165] Moreover, while operations can be depicted in a particular, serial order, this should not be understood as requiring or implying that such operations be performed in the order illustrated. Rather, many of the operations can be performed in parallel, or in any suitably ordered manner. Additionally, although a particular order of the operations is depicted and discussed, this should not be taken as requiring or implying that the order of the operations is "critical," or that the implementation of the disclosed techniques is dependent on the satisfactory completion of any previously described or otherwise illustrated operations describing the features of the present disclosure. Still further, while the above discussion has focused on the use of the features of the present disclosure in the context of a single embodiment, it should be recognized that the features of the present disclosure can be combined in any suitable manner in any number of embodiments.
[0166] Although the subject matter has been described in language specific to structural features and / or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
Claims
1. A method of executing a command in a command line tool, characterized by, Applied to a terminal, comprising: Obtaining a target command identifier in a command line interface, wherein the command line interface is an interactive interface of the command line tool, the command line tool comprises a preset configuration file, and the preset configuration file contains configuration information of files relied on by command running in the command line tool; Obtaining a file identifier of a downloaded file corresponding to the target command identifier; According to the file identifier, the target file identifier corresponding to the target command identifier in the configuration information is queried to determine the file identifier of the to-be-downloaded file; According to the file identifier of the to-be-downloaded file, the to-be-downloaded file is downloaded from the server, and the target command is executed in combination with the to-be-downloaded file and the downloaded file corresponding to the target command identifier.
2. The method of claim 1, wherein, Before obtaining the target command identifier in the command line interface, further comprising: Sending a version query request of the command line tool to the server, and obtaining version information of the command line tool returned by the server; If it is determined according to the version information that the command line tool meets preset version update conditions, the version-updated command line tool is downloaded; Install the version-updated command line tool.
3. The method of claim 1, wherein, The target command identifier in the command line interface is obtained, comprising: Obtaining a command character input in the command line interface; If the command character meets a preset naming condition, the target command identifier is determined according to the command character.
4. The method of claim 1, wherein, The file identifier of the downloaded file corresponding to the target command identifier is obtained, comprising: According to the target command identifier, the storage path corresponding to the target command is queried, wherein the storage path is used to store the file relied on by the target command running; If there is no storage path corresponding to the target command, it is determined that the file corresponding to the target command identifier has not been downloaded. If there is a storage path corresponding to the target command, the file identifier of the downloaded file corresponding to the target command identifier is obtained according to the storage path.
5. The method of claim 4, wherein, If the file corresponding to the target command identifier has not been downloaded, the target file identifier corresponding to the target command identifier in the configuration information is taken as the file identifier of the to-be-downloaded file. If the file corresponding to the target command identifier has been downloaded, the storage time of the downloaded file corresponding to the target command identifier is obtained; 6. The method of claim 4, wherein, If the storage time exceeds a preset update detection threshold, the preset configuration file is downloaded from the server; According to the file version information corresponding to the target command identifier, the to-be-updated file in the downloaded file corresponding to the target command identifier is determined according to the text version information; According to the file identifier of the to-be-updated file, the file identifier of the to-be-downloaded file is determined. The target command is executed in combination with the to-be-downloaded file and the downloaded file corresponding to the target command identifier, comprising: 7. The method of claim 1, wherein, obtaining a target parameter corresponding to a target command, wherein the target command comprises a target command identifier and a target parameter, and the target parameter is a parameter required for running the target command; executing the target command based on the to-be-downloaded file, the downloaded file, and the target parameter.
8. The method of claim 1, wherein, After the target command is executed based on the to-be-downloaded file and the downloaded file corresponding to the target command identifier, the method further comprises: generating a command execution record according to an execution time and an execution frequency of the target command; when a record reporting condition is met, sending the command execution record and a user identifier to the server, so that the server generates a command analysis result based on the command execution record and the user identifier.
9. An apparatus for executing a command in a command line tool, characterized by The application is applied to a terminal and comprises: a command identifier obtaining module configured to obtain a target command identifier in a command line interface, wherein the command line interface is an interactive interface of a command line tool, the command line tool comprises a preset configuration file, and the preset configuration file contains configuration information of files on which command running in the command line tool depends; a file identifier obtaining module configured to obtain a file identifier of a downloaded file corresponding to the target command identifier; a downloaded file determining module configured to query a target file identifier corresponding to the target command identifier in the configuration information according to the file identifier, and determine a file identifier of a to-be-downloaded file; a command executing module configured to download the to-be-downloaded file from a server according to the file identifier of the to-be-downloaded file, and execute a target command based on the to-be-downloaded file and the downloaded file corresponding to the target command identifier.
10. An electronic device, comprising: The electronic device comprises: one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method for executing a command in a command line tool according to any one of claims 1-8.
11. A storage medium containing computer-executable instructions, wherein: The computer executable instructions, when executed by a computer processor, are used to execute the method for executing a command in a command line tool according to any one of claims 1-8.