-
Notifications
You must be signed in to change notification settings - Fork 944
Architecture Guide
Page under construction.
The CF CLI master
branch contains both the V6 and V7 CLIs:
-
main.go
(Orange): Entry point into the CF CLI. - Command Lists (Grey): List of CLI commands contained in that version of the CF CLI. This is dependent on the build
tags
provided to GoLang at compile time. - Command Packages (Yellow): These packages manage the UX/UI logic for each individual command.
- Actor Packages (Teal): These packages manage the business logic for the entire CLI. The V6 CLI actors are divided by Cloud Controller API version; the push and V2/V3 actors are required to mitigate the complexity of integrating the V2 and V3 API versions. The V7 CLI utilizes the V7 Actor package for V7 specific commands.
- API Packages (Green): These packages manage the API requests made to the Cloud Controller/UAA/Networking/etc. These API requests do not contain any business logic; they are simple abstractions of individual API requests.
- Plugin Packages/Legacy Code (Red): These packages manage the CLI Plugin interface as well as the Legacy CLI code. The plugin interface exclusively talks to the Legacy Code. The Legacy Code only interacts with the Cloud Controller V2 API, UAA API, and the Routing API.
When a CLI command is executed, the following process occurs:
- All the command line arguments (aka
os.Args
) are provided to the go-flags package with the appropriate command list. - Based on the
command
tag from the command list and the command line arguments, go-flags will instantiate the correct command struct and populate thestruct
's fields based off of the providedshort
/long
flags listed in the commandstruct
's tags. - The command's
Setup
function is called with a preloaded UI and an in memory copy of the CLI config. ThisSetup
function creates all the necessary API clients and Actors required for the command. - The command's
Execute
function is called; theExecute
function [generally] runs through the following:- Validates/sanitizes the user provided input.
- API version checks based on provided input.
- Verifies API targets based on command requirements.
- Outputs "flavor" text to indicate to the user that desired action is about to be processed.
- Calls appropriate Actor function(s) to perform command's action. (See step #5 for more information)
- Displays output of Actor function(s) depending on command's intent.
- When an Actor function is called, one or more API calls are made to the Cloud Controller, UAA, Networking API, etcetera. Any complex logic regarding the response of these APIs are handled within the Actor function, returning the final result of said API calls or an error indicating why the Actor function could not proceed.
- When a command has returned from its
Execute
, any changes to the CLI config are written to disk.
When the CLI's main
package is compiled without the V7
tag (or with the !V7
tag), the V6 CLI's command list is used in the generated binary. This command list points exclusively to the commands under command/v6
, command/common
, and command/plugin
. Each command uses some combination of the v2action.Actor
, v3action.Actor
, v2v3action.Actor
, and the Push.Actor
to perform the desired action.
The following is a list of files exclusive to the V6 CLI:
└── command
└── common
├── command_list_v6.go # Different Command list
└── internal
├── help_all_display_v6.go # Different help list
└── help_common_display_v6.go # Different help list
When the CLI's main
package is compiled with the V7
tag, the V7 CLI's command list is used in the generated binary. The V7 CLI's command list is identical to the V6 CLI's command list, with the exception of some command/v7
commands overwriting the analogous command/v6
commands. These command/v7
commands should exclusively use the actor/v7action
package to perform their business operations.
Note: While the Cloud Controller V3 API is transitioning, there may be a need to temporarily use the
v2action
package to fill in missing functionality in thev7action
package.
The following is a list of files exclusive to the V7 CLI:
├── actor
│ └── v7actor # V7 specific business logic
└── command
├── common
│ ├── command_list_v7.go # Different Command list
│ └── internal
│ ├── help_all_display_v7.go # Different help list
│ └── help_common_display_v7.go # Different help list
└── v7 # Over written V7 versions of V6 commands
The CLI architecture described above is our Refactored code. Our unrefactored Legacy code lives in the cf
directory. Our legacy code does not follow our layered Command/Actor/API paradigm. Legacy commands are in the process of being refactored into the new architecture.