Documentation
¶
Overview ¶
Package cli wires the cobra command tree and the process exit codes. It is thin: every command resolves its profile and clients through App and then calls a service or the Graph layer. All output goes through output.Printer, which is what the forbidigo linter enforces.
Index ¶
- Variables
- func Main(args []string) int
- func MainWith(app *App, args []string) int
- type App
- func (a *App) Auth(ctx context.Context) (*auth.Client, error)
- func (a *App) Choose(question string, options []string) (int, error)
- func (a *App) Config() (*config.Config, error)
- func (a *App) ConfigFileExists() bool
- func (a *App) ConfigPath() string
- func (a *App) Effective() (config.Effective, error)
- func (a *App) Execute(ctx context.Context, args []string) error
- func (a *App) Graph(ctx context.Context) (*graph.Client, error)
- func (a *App) GraphBaseURL() string
- func (a *App) Interactive() bool
- func (a *App) Me(ctx context.Context) (graph.Me, error)
- func (a *App) Paths() (store.Paths, error)
- func (a *App) Root() *cobra.Command
- func (a *App) SetHooks(h Hooks)
- type Hooks
- type Me
Constants ¶
This section is empty.
Variables ¶
var ( Version = "dev" Commit = "none" Date = "unknown" )
Version information, injected at build time with
-ldflags "-X github.com/floriscornel/teams-cli/internal/cli.Version=… -X github.com/floriscornel/teams-cli/internal/cli.Commit=… -X github.com/floriscornel/teams-cli/internal/cli.Date=…"
(see the build/install tasks in mise.toml and .goreleaser.yaml).
Functions ¶
Types ¶
type App ¶
type App struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
// Clock is injectable so relative output and retry math are deterministic.
Clock clock.Clock
// Hooks are the in-process test seams (see hooks.go). Production leaves them
// empty: there is no flag or environment variable that can set them.
Hooks Hooks
Printer *output.Printer
// contains filtered or unexported fields
}
App carries everything a command needs: the streams, the resolved profile and lazily built clients. One App per process run keeps tests able to run the CLI in-process with their own streams and fakes.
func New ¶
New builds an App around the given streams. The Printer is built here rather than only in Execute so that any App method (confirm, Debugf) is safe to call before a command runs; Execute rebuilds it once the global flags are known.
func (*App) Choose ¶
Choose implements ref.Chooser. The options are printed to stderr so stdout stays parseable, and the answer is a 1-based number.
func (*App) ConfigFileExists ¶
ConfigFileExists reports whether the config file is on disk.
func (*App) ConfigPath ¶
ConfigPath is the config file location: TEAMS_CONFIG when set, otherwise the platform default. It deliberately does not depend on the selected profile, so loading the config can never recurse into resolving a profile.
func (*App) Graph ¶
Graph returns a Graph client for the selected profile, building it on first use. TEAMS_ACCESS_TOKEN and the cached account both flow through auth.Client, which is a graph.TokenSource.
func (*App) GraphBaseURL ¶
GraphBaseURL is the service root a request goes to, for the few places that have to spell it out in a body: an odata bind URL and a --dry-run document.
func (*App) Interactive ¶
Interactive implements ref.Chooser: a name that matches several objects may be disambiguated on a terminal, and only there.
type Hooks ¶
type Hooks struct {
// ConfigPath overrides the config file (tests otherwise use TEAMS_CONFIG).
ConfigPath string
// GraphBaseURL points the Graph client at fakegraph.
GraphBaseURL string
// GraphHTTPClient is the HTTP client for Graph calls.
GraphHTTPClient *http.Client
// AuthHTTPClient is MSAL's HTTP client (fakeidp's TLS client).
AuthHTTPClient *http.Client
// AuthAuthority overrides the MSAL authority URL (fakeidp's authority).
AuthAuthority string
// AuthOpenURL replaces the browser opener (fakeidp's in-process browser).
AuthOpenURL func(url string) error
// DisableInstanceDiscovery is required by fakeidp: its authority host is not
// a trusted Microsoft host, so MSAL would otherwise call instance discovery.
DisableInstanceDiscovery bool
// Environ replaces os.Environ() for the auth and config layers.
Environ []string
// Sleeper replaces the retry delay so throttling tests stay fast.
Sleeper graph.Sleeper
// Recorder observes Graph traffic for the Layer 6 contract validation.
Recorder graph.Recorder
// GrantedScopes replaces the scopes read from the token, so tests can
// exercise the scope gate without a full MSAL login. nil means "read the
// token".
GrantedScopes []string
// UpdateBaseURL points the update check at a fake GitHub API. Empty means
// the real api.github.com; like the other URLs here there is no flag or
// environment variable for it, so a released binary cannot be redirected.
UpdateBaseURL string
// UpdateHTTPClient is the HTTP client for the update check.
UpdateHTTPClient *http.Client
}
Hooks are the in-process seams the Layer 5 tests use to point the real CLI at fakegraph and fakeidp.
PLAN.md requires that released binaries expose no test-only URL override: there is deliberately no flag and no environment variable for these fields, so a user cannot set them. The test harness sets them on the App it constructs, and the release smoke test asserts the shipped binary has no such flag.
type Me ¶
type Me struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
UserPrincipalName string `json:"userPrincipalName,omitempty"`
Mail string `json:"mail,omitempty"`
}
Me is the signed-in user, as returned by GET /me. Only the fields the CLI shows are modelled; the `--json` schema is exactly this struct.
GET /me needs User.Read, which reaches only the signed-in user - which is all whoami wants (refs/graph/api-reference/v1.0/includes/permissions/user-get-permissions.md:3).