A method and apparatus for automatically generating command line code

By automatically generating command-line code for the Zephyr system, the problem of low efficiency in manual code writing is solved, achieving efficient and reliable code generation, suitable for large-scale or rapidly expanding software projects.

CN119829033BActive Publication Date: 2025-11-21SHENZHEN JAGUAR MICROSYSTEMS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411900094.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-11-21
Estimated Expiration
2044-12-19

AI Technical Summary

Technical Problem

In the Zephyr system, manually writing command-line code is inefficient and difficult to meet the needs of large-scale or rapidly expanding software projects.

Method used

By acquiring and parsing the command line information file, a list of command information is generated, and command line code is automatically generated according to preset code rules, including first-level command registration rules, second-level command registration rules, and function body rules.

Benefits of technology

It reduces the workload of software engineers writing code manually, improves the efficiency of writing command-line code, reduces the probability of human error, and generates code with a unified format and structure, thus shortening the development cycle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829033B_ABST
    Figure CN119829033B_ABST
Patent Text Reader

Abstract

The application relates to a method and device for automatically generating command line codes, which comprises the following steps: parsing command information list from a command line information file, including file name and form and description of each command line; then, according to preset code rules (including first-level and second-level command registration rules and function body rules), traversing each command line information of the command information list and generating corresponding command line codes; finally, creating a named command line code file according to the generated codes and the file name. The method and device are aimed at simplifying the development process of a command line tool and improving the code generation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software development technology, specifically to a method and apparatus for automatically generating command-line code. Background Technology

[0002] Zephyr is an open-source real-time operating system (RTOS) designed for Internet of Things (IoT) devices. It is suitable for a wide range of IoT devices, including sensors, wearables, smart home devices, and industrial automation equipment. Due to its open-source nature, developers can customize and optimize it to meet their specific needs.

[0003] The Zephyr system provides a command-line interface as a human-computer interaction window, allowing users to input commands to control program execution. In traditional software development, software engineers often need to manually write command-line code, which contains multiple command-line instructions. Inputting this code into the command-line interface executes a series of operations at once. However, manually writing command-line code is time-consuming, inefficient, and unsuitable for large-scale or rapidly scalable software projects. Summary of the Invention

[0004] The purpose of this application is to provide a method, apparatus, and computer program product for automatically generating command-line code, so as to improve the efficiency of writing command-line code for the Zephyr system.

[0005] To achieve the above objectives, according to a first aspect of this application, a method for automatically generating command-line codes is provided, the method comprising:

[0006] Obtain and parse the command line information file to obtain a list of command information to be generated; wherein, the list of command information includes a file name and multiple command line information, each of the command line information includes at least a command line format and a command line description, 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] The command information list is traversed, and corresponding command line code is generated for each command line information according to preset code rules. The code rules include at least first-level command registration rules, second-level command registration rules, and function body rules. The first-level command registration rules describe the registration code format of the first-level command, the second-level command registration rules describe the registration code format of the second-level command, and the function body rules describe the code format of the generated function body. The first-level command is the operation type or operation object of the command, and the second-level command is a subcommand under the first-level command.

[0008] A command-line code file named with the given filename is obtained based on the generated command-line code and the filename.

[0009] According to a second aspect of this application, an apparatus for automatically generating command-line code is provided, characterized in that the apparatus comprises:

[0010] The command information list acquisition module is 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 command line information includes at least a command line format and a command line description, 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;

[0011] The command line code generation module is used to traverse the command information list and generate corresponding command line code for each command line information according to preset code rules. The code rules include at least first-level command registration rules, second-level command registration rules, and function body rules. The first-level command registration rules describe the registration code format of the first-level command, the second-level command registration rules describe the registration code format of the second-level command, and the function body rules describe the code format of the generated function body. The first-level command is the operation type or operation object of the command, and the second-level command is a subcommand under the first-level command.

[0012] The code file generation module is used to obtain a command-line code file named after the generated command-line code and the file name.

[0013] According to a third aspect of this application, a computer program product is provided, including computer program instructions that instruct a computer device to perform an operation corresponding to the method described in the first aspect.

[0014] The above-mentioned method, apparatus, and computer program product for automatically generating command line code have the following beneficial effects:

[0015] By automatically generating command-line code, the workload of software engineers in manually writing code is reduced, greatly improving the efficiency of command-line code writing. It can reduce the errors that are easily caused by human factors when manually writing code, and improve the reliability of the code. Through preset code rules, the generated command-line code has a uniform format and structure. For large-scale software projects or those that need to be rapidly expanded, 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. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings required in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating a method for automatically generating command-line code in one embodiment of this application.

[0018] Figure 2 This is a flowchart of steps S10 and S20 in one embodiment of this application.

[0019] Figure 3 This is a schematic diagram of the structure of an apparatus for automatically generating command line code in one embodiment of this application. Detailed Implementation

[0020] The detailed description of the accompanying drawings is intended to illustrate the present embodiments of this application and is not intended to represent only the forms in which this application can be implemented. It should be understood that the same or equivalent functions can be accomplished by different embodiments intended to be included within the spirit and scope of this application.

[0021] See Figures 1-2 One embodiment of this application provides a method for automatically generating command-line code, the method comprising:

[0022] Step S10: Obtain and parse the command line information file to obtain a list of command information to be generated; wherein, the list of command information includes a filename and multiple command line information, each of the command line information includes at least a command line format and a command line description, 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.

[0023] Specifically, the command-line information file can be any structured format, such as JSON, XML, YAML, etc., which are easy for machines to parse and use. The command-line information file is provided by the software developer.

[0024] The parsing refers to converting the contents of the command-line information file into a data structure that the program can understand and manipulate. During the parsing process, the program reads the data according to the file format rules and converts it into a data structure in memory, namely the command information list. The command information list is the result of the parsing process. It is a data set that contains all the information needed to generate the command-line code.

[0025] The filename is the name used to name the final generated command-line code file.

[0026] The command line information is the basic unit in the command information list, and each command line information contains at least the following command line format and command line description;

[0027] The command-line format describes the syntactic structure of commands in the command-line interface.

[0028] The command-line description is a brief explanation of the purpose of the command, which helps the user understand the function of the command.

[0029] Through step S10, the program can understand how each command should be invoked in the command-line interface and the specific function of each command. This information is the basis for automatically generating command-line code, informing 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 code for each command line information according to preset code rules; wherein, the code rules include at least first-level command registration rules, second-level command registration rules, and function body rules, the first-level command registration rules are used to describe the registration code format of the first-level command, the second-level command registration rules are used to describe the registration code format of the second-level command, and the function body rules are used to describe the code format of the generated function body; the first-level command is the operation type or operation object of the command, and the second-level command is the subcommand under the first-level command.

[0031] Specifically, in step S20, the program checks each command line message in the command information list one by one. Traversal means that the program processes each command line message in a certain order (e.g., from the first command line message to the last command line message in the list).

[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 conforms to 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 rules describe how to register first-level commands. First-level commands are usually the highest-level commands, and they represent operation types or operation objects. For example, nivc (Nested Vectored Interrupt Controller) indicates that the command is an operation related to nivc.

[0034] Second-level command registration rules describe how to register second-level commands. Second-level commands are subcommands of first-level commands, and they usually provide more specific operation options. For example, test_register indicates that the command is to test the register status or function of the NIVC.

[0035] The function body rules describe how to write the function body that executes the command. The function body contains the code that is actually executed when the command is called.

[0036] For each command line entry in the command information list, the program generates corresponding code according to the rules mentioned above. This process includes: determining whether the command is a first-level command or a second-level command; generating command registration code using the corresponding first-level or second-level command registration rules; and generating function code to be executed when the command is called using function body rules.

[0037] Through step S20, the program can automatically generate structured, compilable command-line code that can be directly integrated into the application to achieve the functionality of the command-line interface.

[0038] Step S30: Obtain a command line code file named after the generated command line code and the file name.

[0039] Specifically, the filename is obtained by parsing the command line information file. This filename will be used to name the command line code file to be created. The generated command line code is combined with the specified filename to create a file named with that filename. The command line code is written into the file and saved to obtain the command line code file.

[0040] This embodiment of the method automatically generates command-line code, reducing the workload of software engineers in manually writing code and greatly improving the efficiency of command-line code writing. It can reduce the errors that are easily caused by human factors when manually writing code and improve the reliability of the code. 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 rapidly expanded, automatic generation of command-line code can significantly shorten the development cycle and has significant advantages in improving development efficiency, reducing costs, and improving code quality.

[0041] According to the methods of the above embodiments, in some embodiments, each command line information further includes at least one parameter information, the parameter information including a parameter name and a parameter description;

[0042] The code rules also include parameter rules, which are used to describe the generated parameter-related code format.

[0043] Specifically, the command-line information may contain zero or at least one parameter. Some command-line information may not contain parameters because no additional parameter input is required when executing the command. The parameter name refers to an identifier used to specify the parameter, typically a word or phrase, used to pass data or configuration options in the command line. The parameter description provides a brief explanation of the parameter's purpose, helping the user understand its function and how to use it. Code rules define how to generate command-line related code. In this embodiment, code rules include not only command rules but also parameter rules, which describe how to generate parameter-related code formats.

[0044] According to the methods described in the above embodiments, in some embodiments, the parameter rules include fixed parameter rules and optional parameter rules. The fixed parameter rules are used to describe the code format related to the generated fixed parameters, and the optional parameter rules are used to describe the code format related to the generated optional parameters.

[0045] Specifically, in the implementation method, parameter rules are divided into fixed parameter rules and optional parameter rules.

[0046] The fixed parameter rules are used to describe the code format of parameters that must be provided when executing a command. Fixed parameters are those that are necessary for the execution of a command; without them, the command cannot be executed correctly. Fixed parameters usually have a fixed position and order.

[0047] The optional parameter rules are used to describe the code format 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 methods described in the above embodiments, in some embodiments, each command line information further includes remarks information, which are additional information for the command line 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 remarks. The remarks are additional descriptions of the command line, primarily intended to help users better understand and use it.

[0050] For example, explain the purpose of the command: provide an explanation of the basic functions and usage scenarios of the command.

[0051] For example, notes: pointing out special situations or potential problems that may need to be considered when using commands.

[0052] For example, dependencies: describe 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 represented as follows:

[0054]

[0055] The command information list above contains a command line message, where "nvic_cmd.c" is the filename, and "cmd": "nvic test_register<int_id> [<tes_sel> The command line is defined as follows: "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 methods described in the above embodiments, in some embodiments, the code rules include at least function comment header rules, which are used to describe the code format of the generated function comment information.

[0057] Specifically, in software development, function comment headers are used to provide descriptive information about a function before its definition. These comments aim to explain the function's purpose, parameters, return value, and any possible side effects. In the implementation method, the code rules include at least function comment header rules, which the program follows to create the function's comment information when generating code.

[0058] Corresponding to the methods in the above embodiments, see [link to relevant documentation]. Figure 3 Another embodiment of this application provides an apparatus for automatically generating command-line code, which can be used to execute the methods of the above embodiments, including:

[0059] Command information list acquisition module 1 is used to acquire and parse command line information files to obtain the command information list to be generated; wherein, the command information list includes filenames and multiple command line information, each command line information includes at least a command line format and a command line description, 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] Command line code generation module 2 is used to traverse the command information list and generate corresponding command line code for each command line information according to preset code rules; wherein, the code rules include at least first-level command registration rules, second-level command registration rules, and function body rules, the first-level command registration rules are used to describe the registration code format of the first-level command, the second-level command registration rules are used to describe the registration code format of the second-level command, and the function body rules are used to describe the code format of the generated function body; the first-level command is the operation type or operation object of the command, and the second-level command is the subcommand under the first-level command;

[0061] The code file generation module 3 is used to obtain a command line code file named after the generated command line code and the file name.

[0062] According to the apparatus of the above embodiments, in some embodiments, each command line information further includes at least one parameter information, the parameter information including a parameter name and a parameter description;

[0063] The code rules also include parameter rules, which are used to describe the generated parameter-related code format.

[0064] According to the apparatus of the above embodiments, in some embodiments, the parameter rules include fixed parameter rules and optional parameter rules. The fixed parameter rules are used to describe the code format related to the generated fixed parameters, and the optional parameter rules are used to describe the code format related to the generated optional parameters.

[0065] According to the apparatus described above, in some embodiments, the code rules include at least function comment header rules, which are used to describe the code format of the generated function comment information.

[0066] According to the apparatus of the above embodiments, in some embodiments, each command line information further includes remarks information, which are additional information of the command line to help the user understand the command line.

[0067] It should be noted that the apparatus in this embodiment corresponds to the method in the above embodiments. Therefore, the contents not described in detail in the apparatus of this embodiment can be obtained by referring to the contents of the method in the above embodiments. Hence, the apparatus in this embodiment will not be described in detail.

[0068] Another embodiment of this application provides a computer program product including computer program instructions that instruct a computer device to perform operations corresponding to the methods described in the above embodiments.

[0069] Specifically, the computer program product includes a series of computer program instructions, which are codes written in a computer program that define how to perform specific operations. In this embodiment, these instructions are used to execute the methods of the above embodiments. These program instructions are designed to be loaded onto a computer device and to 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 methods of the above embodiments.

[0070] The various embodiments of this application have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical applications, or technological improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A method for automatically generating command-line code, characterized in that, The method includes: Obtain and parse the command line information file to obtain a list of command information to be generated; wherein, the list of command information includes a file name and multiple command line information, each of the command line information includes at least a command line format and a command line description, 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; The command information list is traversed, and corresponding command line code is generated for each command line information according to preset code rules. The code rules include at least first-level command registration rules, second-level command registration rules, and function body rules. The first-level command registration rules describe the registration code format of the first-level command, the second-level command registration rules describe the registration code format of the second-level command, and the function body rules describe the code format of the generated function body. The first-level command is the operation type or operation object of the command, and the second-level command is a subcommand under the first-level command. A command-line code file named with the given filename is obtained based on the generated command-line code and the filename.

2. The method according to claim 1, characterized in that, Each command-line message also includes at least one parameter message, which includes a parameter name and a parameter description; The code rules also include parameter rules, which are used to describe the generated parameter-related code format.

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 code format related to the generated fixed parameters, and the optional parameter rules are used to describe the code format related to the generated optional parameters.

4. The method according to claim 1, characterized in that, Each command-line message also includes a comment, which is additional information about the command line to help the user understand it.

5. The method according to claim 1, characterized in that, The code rules include at least function comment header rules, which are used to describe the code format of the generated function comment information.

6. An apparatus for automatically generating command-line code, characterized in that, The device includes: The command information list acquisition module is 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 command line information includes at least a command line format and a command line description, 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; The command line code generation module is used to traverse the command information list and generate corresponding command line code for each command line information according to preset code rules. The code rules include at least first-level command registration rules, second-level command registration rules, and function body rules. The first-level command registration rules describe the registration code format of the first-level command, the second-level command registration rules describe the registration code format of the second-level command, and the function body rules describe the code format of the generated function body. The first-level command is the operation type or operation object of the command, and the second-level command is a subcommand under the first-level command. The code file generation module is used to obtain a command-line code file named after the generated command-line code and the file name.

7. The apparatus according to claim 6, characterized in that, Each command-line message also includes at least one parameter message, which includes a parameter name and a parameter description; The code rules also include parameter rules, which are used to describe the generated parameter-related code format.

8. The apparatus 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 code format related to the generated fixed parameters, and the optional parameter rules are used to describe the code format related to the generated optional parameters.

9. The apparatus according to claim 6, characterized in that, The code rules include at least function comment header rules, which are used to describe the code format of the generated function comment information.

10. A computer program product, characterized in that, It includes computer program instructions that instruct a computer device to perform an operation corresponding to the method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Command line function code generation method and device and computer readable storage medium

    CN115794057A

  • Information processing method and device, equipment and storage medium

    CN117519666A