Method and device for automatically generating command line code
By automatically generating the command line code of the Zephyr system, the problem of inefficient writing of manual code is solved, and the code is quickly generated and efficiently written, which is suitable for large-scale or rapidly expanding software projects.
Patent Information
- Application Number
- CN202411900094.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-19
AI Technical Summary
In traditional software development methods, it takes a lot of time to manually write command line code for Zephyr system, and is less efficient to write, making it difficult to cope with large-scale or fast-scaling software projects.
Provides a method and device for automatically generating command line code. By obtaining and parsing command line information files, traversing the command information list, generating corresponding command line codes according to preset code rules, and generating command line code files named after file names.
It significantly improves the efficiency of writing command line code, reduces the occurrence of human errors, and the generated code has a unified format and structure, which can significantly shorten the development cycle of large-scale or rapid expansion of software projects.
Smart Images

Figure CN119829033A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development technology, and in particular to a method and device for automatically generating command line codes. Background Art
[0002] The Zephyr system is an open source real-time operating system (RTOS) designed for Internet of Things (IoT) devices. The Zephyr system is suitable for a variety of IoT devices, including sensors, wearable devices, smart home devices, industrial automation equipment, etc. Due to its open source nature, developers can customize and optimize it according to their needs.
[0003] The Zephyr system provides a command line interface as a window for human-computer interaction. Users can enter commands through the command line interface to control the operation of the program. In traditional software development methods, software engineers are often required to manually write command line codes, which contain multiple command line instructions. By entering these written command line codes into the command line interface, a series of operations can be executed at one time. However, manually writing command line codes takes a lot of time and has low writing efficiency, making it difficult to meet the needs of large-scale or rapidly expanding software projects. Summary of the invention
[0004] The purpose of this application is to propose a method and device for automatically generating command line code, and a computer program product to improve the efficiency of writing command line code for the Zephyr system.
[0005] To achieve the above objective, according to a first aspect of the present application, a method for automatically generating command line code is provided, the method comprising:
[0006] Acquire and parse the command line information file to obtain a command information list to be generated; wherein the command information list includes a file name and multiple command line information, each of which includes at least a command line format and a command line description, wherein the command line format is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line;
[0007] Traversing the command information list, generating corresponding command line codes for each command line information according to preset code rules; wherein the code rules at least include primary command registration rules, secondary command registration rules and function body rules, the primary command registration rules are used to describe the registration code format of the primary command, the secondary command registration rules are used to describe the registration code format of the secondary command, and the function body rules are used to describe the code format of the generated function body; the primary command is the operation type or operation object of the command, and the secondary command is a subcommand under the primary command;
[0008] A command line code file named with the file name is obtained according to the generated command line code and the file name.
[0009] According to a second aspect of the present application, a device for automatically generating command line code is provided, characterized in that the device comprises:
[0010] A command information list acquisition module, used to acquire and parse the command line information file to obtain the command information list to be generated; wherein the command information list includes a file name and multiple command line information, each of which includes at least a command line form and a command line description, wherein the command line form is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line;
[0011] A command line code generation module, used to traverse the command information list and generate corresponding command line codes for each command line information according to preset code rules; wherein the code rules at least include a primary command registration rule, a secondary command registration rule and a function body rule, wherein the primary command registration rule is used to describe the registration code format of the primary command, the secondary command registration rule is used to describe the registration code format of the secondary command, and the function body rule is used to describe the code format of the generated function body; the primary command is an operation type or an operation object of a command, and the secondary command is a subcommand under the primary command;
[0012] The code file generating module is used to obtain a command line code file named with the file name according to the generated command line code and the file name.
[0013] According to a third aspect of the present application, a computer program product is provided, comprising computer program instructions, wherein the computer program instructions instruct a computer device to perform operations corresponding to the method described in the first aspect.
[0014] The above method and device for automatically generating command line code, and computer program product have the following beneficial effects:
[0015] By automatically generating command line code, the workload of software engineers in manually writing code is reduced, the efficiency of command line code writing is greatly improved, the occurrence of errors caused by human factors in manually writing code can be reduced, and the reliability of the code can be improved; through preset code rules, the generated command line code has a unified format and structure; for large-scale software projects or those that need to be expanded rapidly, automatically generating command line code can significantly shorten the development cycle, and has significant advantages in improving development efficiency, reducing costs, and improving code quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0017] Figure 1 This is a flowchart of a method for automatically generating command line codes in one embodiment of the present application.
[0018] Figure 2 This is a specific flow chart of step S10 and step S20 in one embodiment of the present application.
[0019] Figure 3 A schematic diagram of a device for automatically generating command line code in an embodiment of the present application DETAILED DESCRIPTION
[0020] The detailed description of the drawings is intended as an illustration of the current embodiment of the present application, and is not intended to represent the only form in which the present application can be implemented. It should be understood that the same or equivalent functions can be accomplished by different embodiments intended to be included in the spirit and scope of the present application.
[0021] See also Figures 1-2 An embodiment of the present application provides a method for automatically generating command line code, the method comprising:
[0022] Step S10, obtaining and parsing the command line information file to obtain the command information list that needs to be generated; wherein the command information list includes a file name and multiple command line information, each of the command line information includes at least a command line form and a command line description, the command line form is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line.
[0023] Specifically, the command line information file may be in any structured format, such as JSON, XML, YAML, etc., which are convenient for machine parsing and use. The command line information file is provided by a software developer.
[0024] The parsing refers to converting the file content of the command line information file into a data structure that can be understood and operated by the program. During the parsing process, the program reads the data according to the rules of the file format and converts it into a data structure in the memory, namely, a command information list. The command information list is the result of the parsing process. It is a data set that contains all the information required to generate the command line code.
[0025] The file name is used to name the command line code file that is finally generated.
[0026] The command line information is a basic unit in the command information list, and each command line information includes at least the following command line format and command line description;
[0027] The command line format describes the grammatical structure of the command in the command line interface.
[0028] The command line description is a brief description of the purpose of the command, which helps the user understand the effect of the command.
[0029] Through step S10, the program can understand how each command should be called in the command line interface and the specific function of each command. This information is the basis for automatically generating command line code, telling the program which commands need to be created and how these commands should be formatted and described.
[0030] Step S20, traverse the command information list, and generate corresponding command line codes for each command line information according to preset code rules; wherein the code rules include at least a first-level command registration rule, a second-level command registration rule and a function body rule, the first-level command registration rule is used to describe the registration code format of the first-level command, the second-level command registration rule is used to describe the registration code format of the second-level command, and the function body rule is used to describe the code format of the generated function body; the first-level command is an operation type or an operation object of a command, and the second-level command is a subcommand under the first-level command.
[0031] Specifically, in step S20, the program checks each command line information in the command information list one by one, and traversal means that the program processes each command line information in a certain order (for example, from the first command line information in the list to the last command line information).
[0032] Code rules are a set of guidelines or templates that define how to convert command line information into code. Code rules ensure that the generated code meets the requirements of a specific programming language and framework. In this embodiment, code rules include at least first-level command registration rules, second-level command registration rules, and function body rules.
[0033] The first-level command registration rule is used to describe how to register the first-level commands. The first-level commands are usually the highest-level commands. They represent the operation type or operation object. For example, nivc (Nested Vectored Interrupt Controller) indicates that the command is an operation related to nivc.
[0034] Secondary command registration rules are used to describe how to register secondary commands. Secondary commands are subcommands of primary commands. They usually provide more specific operation options. For example, test_register indicates that the command is to test the register status or function of nivc.
[0035] Function body rules describe how to write the function body of an execution command. The function body contains the code that is actually executed when the command is called.
[0036] For each command line information in the command information list, the program will generate the corresponding code according to the above rules. This process includes: determining whether the command is a first-level command or a second-level command; using the corresponding first-level or second-level command registration rules to generate command registration code; using function body rules to generate function code that is executed when the command is called.
[0037] Through step S20, the program can automatically generate structured and compilable command line codes, which can be directly integrated into the application program to implement the functions of the command line interface.
[0038] Step S30: obtaining a command line code file named with the file name according to the generated command line code and the file name.
[0039] Specifically, the file name is parsed from the command line information file, and this file name will be used to name the command line code file to be created. The generated command line code is combined with the specified file name to create a file named after the file name, and the command line code is written into the file and saved to obtain the command line code file.
[0040] The method of this embodiment reduces the workload of software engineers in manually writing codes by automatically generating command line codes, greatly improves the efficiency of writing command line codes, can reduce the occurrence of errors easily caused by human factors in manually writing codes, and improves the reliability of codes; through preset code rules, the generated command line codes have a unified format and structure; for large-scale software projects or those that need to be expanded rapidly, automatically generating command line codes can significantly shorten the development cycle, and has significant advantages in improving development efficiency, reducing costs, and improving code quality.
[0041] According to the above embodiment method, in some embodiments, each of the command line information further includes at least one parameter information, and the parameter information includes a parameter name and a parameter description;
[0042] The code rules also include parameter rules, and the parameter rules are used to describe the generated parameter-related code format.
[0043] Specifically, the command line information may contain 0 or at least one parameter information, and some command line information does not contain parameters because no additional parameter input is required when executing the command. The parameter name refers to an identifier used to specify a parameter, usually a word or a phrase, used to pass data or configuration options in the command line; the parameter description is a brief description of the parameter's purpose, which helps users understand the function of the parameter and how to use it. The code rules define how to generate code related to the command line. In this embodiment, the code rules include not only command rules, but also parameter rules. The parameter rules are used to describe how to generate code formats related to parameters.
[0044] According to the above embodiment method, in some embodiments, the parameter rules include fixed parameter rules and optional parameter rules, the fixed parameter rules are used to describe the generated code format related to fixed parameters, and the optional parameter rules are used to describe the generated code format related to optional parameters.
[0045] Specifically, in the embodiment method, parameter rules are divided into fixed parameter rules and optional parameter rules.
[0046] The fixed parameter rules are used to describe the relevant code formats of the parameters that must be provided when executing a command. Fixed parameters are required for command execution. Without them, the command cannot be executed correctly. Fixed parameters usually have fixed positions and orders.
[0047] The optional parameter rules are used to describe the relevant code formats of parameters that can be optionally provided when executing a command. Optional parameters are not required for command execution, but they can be used to modify the behavior of the command or provide additional configuration options.
[0048] According to the above embodiment method, in some embodiments, each command line information further includes remark information, where the remark information is additional information of the command line and is used to help the user understand the command line.
[0049] Specifically, in this embodiment, the command line information may include not only the command itself and related parameter information, but also remark information, which is an additional description of the command line, and its main purpose is to help users better understand and use the command line.
[0050] For example, describe the purpose of a command: provide a description of the basic functions and usage scenarios of the command.
[0051] Another example is Notes: Point out special circumstances or potential problems that you may need to pay attention to when using a command.
[0052] Another example is dependency: it describes other software or configurations that a command may depend on.
[0053] Taking the nvic module command line as an example, the command information list can be expressed as:
[0054]
[0055] The above command information list contains a command line information, where "nvic_cmd.c" is the file name, and "cmd": "nvic test_register<int_id> [<tes_sel> ]" is the command line, "nvic" is the first-level command, "test_register" is the second-level command, "desc": "Register interrupt callback function for testing" is the command line description, "note": "Note" is the note information, "name": "int_id" is the name of the first parameter, "desc": "Interrupt ID" is the description of the first parameter, "name": "test_sel" is the name of the second parameter, and "desc": "Optional parameter callback function selection" is the description of the second parameter. In the above list, the first parameter int_id is a fixed parameter, and the second parameter test_sel is an optional parameter.
[0056] According to the above embodiment method, in some embodiments, the code rules at least include function annotation header rules, and the function annotation header rules are used to describe the code format of the generated function annotation information.
[0057] Specifically, in software development, the function comment header is used to provide descriptive information about the function before the function definition, and these comments are intended to explain the purpose, parameters, return values, and any possible side effects of the function. In the embodiment method, the code rules at least include function comment header rules, and when generating code, the program will follow these rules to create the comment information of the function.
[0058] Corresponding to the above-mentioned embodiment method, see Figure 3 Another embodiment of the present application provides a device for automatically generating command line codes, which can be used to execute the method of the above embodiment, including:
[0059] A command information list acquisition module 1 is used to acquire and parse a command line information file to obtain a command information list to be generated; wherein the command information list includes a file name and a plurality of command line information, each of which includes at least a command line format and a command line description, wherein the command line format is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line;
[0060] A command line code generation module 2 is used to traverse the command information list and generate corresponding command line codes for each command line information according to preset code rules; wherein the code rules at least include a primary command registration rule, a secondary command registration rule and a function body rule, the primary command registration rule is used to describe the registration code format of the primary command, the secondary command registration rule is used to describe the registration code format of the secondary command, and the function body rule is used to describe the code format of the generated function body; the primary command is an operation type or an operation object of a command, and the secondary command is a subcommand under the primary command;
[0061] The code file generating module 3 is used to obtain a command line code file named with the file name according to the generated command line code and the file name.
[0062] According to the above embodiment device, in some embodiments, each of the command line information further includes at least one parameter information, and the parameter information includes a parameter name and a parameter description;
[0063] The code rules also include parameter rules, and the parameter rules are used to describe the generated parameter-related code format.
[0064] According to the above embodiment device, in some embodiments, the parameter rules include fixed parameter rules and optional parameter rules, the fixed parameter rules are used to describe the generated code format related to the fixed parameters, and the optional parameter rules are used to describe the generated code format related to the optional parameters.
[0065] According to the above embodiment device, in some embodiments, the code rules at least include function annotation header rules, and the function annotation header rules are used to describe the code format of the generated function annotation information.
[0066] According to the above embodiment device, in some embodiments, each of the command line information further includes remark information, where the remark information is additional information of the command line and is used to help the user understand the command line.
[0067] It should be noted that the device of this embodiment corresponds to the method of the above embodiment, so the contents not described in detail in the device of this embodiment can be obtained by referring to the contents of the method of the above embodiment, so they are not repeated in the device of this embodiment.
[0068] Another embodiment of the present application provides a computer program product, including computer program instructions, wherein the computer program instructions instruct a computer device to perform operations corresponding to the method described in the above embodiment.
[0069] Specifically, the computer program product includes a series of computer program instructions, which are codes written in a computer program and define how to perform specific operations. In this embodiment, these instructions are used to execute the method of the above embodiment. These program instructions are designed to be loaded onto a computer device and instruct the device to perform specific operations. In this way, the computer program product provides a complete software solution that can run on various computer devices to implement the method of the above embodiment.
[0070] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for automatically generating command line code, characterized in that: The method comprises: Acquire and parse the command line information file to obtain a command information list to be generated; wherein the command information list includes a file name and multiple command line information, each of which includes at least a command line format and a command line description, wherein the command line format is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line; Traversing the command information list, generating corresponding command line codes for each command line information according to preset code rules; wherein the code rules at least include primary command registration rules, secondary command registration rules and function body rules, the primary command registration rules are used to describe the registration code format of the primary command, the secondary command registration rules are used to describe the registration code format of the secondary command, and the function body rules are used to describe the code format of the generated function body; the primary command is the operation type or operation object of the command, and the secondary command is a subcommand under the primary command; A command line code file named with the file name is obtained according to the generated command line code and the file name.
2. The method according to claim 1, characterized in that: Each of the command line information further includes at least one parameter information, wherein the parameter information includes a parameter name and a parameter description; The code rules also include parameter rules, and the parameter rules are used to describe the format of the generated parameter-related code.
3. The method according to claim 2, characterized in that The parameter rules include fixed parameter rules and optional parameter rules. The fixed parameter rules are used to describe the generated code format related to the fixed parameters, and the optional parameter rules are used to describe the generated code format related to the optional parameters.
4. The method according to claim 1, characterized in that: Each of the command line information further includes remark information, where the remark information is additional information of the command line and is used to help the user understand the command line.
5. The method according to claim 1, characterized in that The code rules at least include function annotation header rules, and the function annotation header rules are used to describe the code format of the generated function annotation information.
6. A device for automatically generating command line code, characterized in that: The device comprises: A command information list acquisition module, used to acquire and parse the command line information file to obtain the command information list to be generated; wherein the command information list includes a file name and multiple command line information, each of which includes at least a command line form and a command line description, wherein the command line form is used to describe the format of the command line, and the command line description is used to indicate the purpose of the command line; A command line code generation module, used to traverse the command information list and generate corresponding command line codes for each command line information according to preset code rules; wherein the code rules at least include a primary command registration rule, a secondary command registration rule and a function body rule, wherein the primary command registration rule is used to describe the registration code format of the primary command, the secondary command registration rule is used to describe the registration code format of the secondary command, and the function body rule is used to describe the code format of the generated function body; the primary command is an operation type or an operation object of a command, and the secondary command is a subcommand under the primary command; The code file generating module is used to obtain a command line code file named with the file name according to the generated command line code and the file name.
7. The device according to claim 6, characterized in that Each of the command line information further includes at least one parameter information, wherein the parameter information includes a parameter name and a parameter description; The code rules also include parameter rules, and the parameter rules are used to describe the format of the generated parameter-related code.
8. The device according to claim 7, characterized in that The parameter rules include fixed parameter rules and optional parameter rules. The fixed parameter rules are used to describe the generated code format related to the fixed parameters, and the optional parameter rules are used to describe the generated code format related to the optional parameters.
9. The device according to claim 6, characterized in that The code rules at least include function annotation header rules, and the function annotation header rules are used to describe the code format of the generated function annotation information.
10. A computer program product, characterized in that The method comprises computer program instructions, wherein the computer program instructions instruct a computer device to execute operations corresponding to the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Web front-end code automatic generation method and device
CN110096263A
Command line function code generation method and device and computer readable storage medium
CN115794057A
Information processing method and device, equipment and storage medium
CN117519666A
Code automatic generation method and device based on command line, equipment and storage medium
CN119105744A
Method and system for program building
US20130139132A1