Skip to content

Structural Project Overview

Thorsten de Buhr edited this page Jul 4, 2023 · 8 revisions

The whole cpackget is built around the cobra module command line parser. After setup, cobra module knows the functions to call after a command has been parsed. The cobra command setup can be found in the cmd/commands/ folder, e.g. add.go, init.go, rm.go.

Initialisation

When the program starts, golang calls all the init functions, which prepare modules and cobra command structures. Then the cobra module is initialized with the gathered command structs.

flowchart LR
    A[main] --> I[Go Init functions]
    I --> I1[Sub command options<br>into corresponding structures<br>for cobra.Command]
    I --> I2[Modules]
    A --> B[Cobra<br>commands.NewCli]
    A --> C[Cobra<br>cmd.Execute]

    B --> D[Set up<br>general commands/options]
    B --> E[Set up<br>sub commands]

    E --> F[Commands with own options:<br>PackCmd<br>PdscCmd<br>IndexCmd<br>InitCmd<br>AddCmd<br>RmCmd<br>ListCmd<br>UpdateIndexCmd<br>ChecksumCreateCmd<br>ChecksumVerifyCmd<br>	SignatureCreateCmd<br>SignatureVerifyCmd]

    D --> G[General commands/options:<br>version<br>quiet<br>verbose<br>pack-root<br>concurrent-downloads<br>timeout<br>]

Loading

Execute

The commandline arguments are parsed through the cobra module, which then calls the corresponding (lambda) function as defined in the command init structs. From there all other functions and modules are called, which are required for the desired functionality.

flowchart LR
    A[main] --> I[Go Init functions]
    A --> B[Cobra<br>commands.NewCli]
    A --> C[Cobra<br>cmd.Execute]
    C --> D[Cobra module<br>Execute]
    D --> E[Before executing command<br>PersistentPreRunE: configureInstaller]
    D --> F[Executes command: RunE: func]
    F --> G[Lambda function inside module,<br>e.g. add command]

Loading
Clone this wiki locally