• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astronomer / astro-cli / 78a63b8e-67c6-4c1c-a99c-85c5b61c40bc

17 Feb 2026 06:51PM UTC coverage: 35.115% (+1.9%) from 33.19%
78a63b8e-67c6-4c1c-a99c-85c5b61c40bc

push

circleci

web-flow
Add `astro api` command (#2006)

2079 of 2468 new or added lines in 13 files covered. (84.24%)

22989 of 65468 relevant lines covered (35.11%)

8.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.22
/cmd/api/api.go
1
// Package api provides the 'astro api' command for making authenticated API requests.
2
package api
3

4
import (
5
        "io"
6
        "os"
7

8
        "github.com/fatih/color"
9
        "github.com/spf13/cobra"
10
)
11

12
// NewAPICmd creates the parent 'astro api' command.
NEW
13
func NewAPICmd() *cobra.Command {
×
NEW
14
        return NewAPICmdWithOutput(os.Stdout)
×
NEW
15
}
×
16

17
// NewAPICmdWithOutput creates the parent 'astro api' command with a custom output writer.
18
func NewAPICmdWithOutput(out io.Writer) *cobra.Command {
6✔
19
        var noColor bool
6✔
20

6✔
21
        cmd := &cobra.Command{
6✔
22
                Use:           "api",
6✔
23
                Short:         "Make authenticated API requests to Astronomer services",
6✔
24
                SilenceErrors: true, // API commands print error bodies themselves; don't let cobra double-print
6✔
25
                SilenceUsage:  true,
6✔
26
                Long: `Make authenticated HTTP requests to Astronomer APIs and print responses.
6✔
27

6✔
28
The 'astro api' command provides direct access to Astronomer's REST APIs.
6✔
29

6✔
30
Available subcommands:
6✔
31
  airflow  Make requests to the Airflow REST API
6✔
32
  cloud    Make requests to the Astro Cloud API (api.astronomer.io)
6✔
33

6✔
34
Use "astro api [command] --help" for more information about a command.`,
6✔
35
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
10✔
36
                        // Cobra does not chain PersistentPreRun hooks: defining one
4✔
37
                        // on a child command silently replaces the parent's. Walk up
4✔
38
                        // to the root and call its PersistentPreRunE explicitly so
4✔
39
                        // that token refresh, logging setup (--verbosity), and
4✔
40
                        // version checking all still happen for api subcommands.
4✔
41
                        if root := cmd.Root(); root != nil && root.PersistentPreRunE != nil {
6✔
42
                                if err := root.PersistentPreRunE(cmd, args); err != nil {
3✔
43
                                        return err
1✔
44
                                }
1✔
45
                        }
46

47
                        // Cobra does not inherit SilenceUsage to subcommands, so propagate
48
                        // it here. The cmd parameter is the actual subcommand being executed,
49
                        // not the parent where PersistentPreRunE is defined.
50
                        //
51
                        // Note: we do NOT propagate SilenceErrors. The parent api command
52
                        // sets SilenceErrors to avoid double-printing HTTP error bodies
53
                        // (SilentError), but subcommands need cobra to print non-silent
54
                        // errors like connection failures.
55
                        cmd.SilenceUsage = true
3✔
56

3✔
57
                        if noColor {
3✔
NEW
58
                                color.NoColor = true
×
NEW
59
                        }
×
60

61
                        return nil
3✔
62
                },
NEW
63
                Run: func(cmd *cobra.Command, args []string) {
×
NEW
64
                        _ = cmd.Help()
×
NEW
65
                },
×
66
        }
67

68
        cmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Disable colorized output")
6✔
69

6✔
70
        cmd.AddCommand(NewAirflowCmd(out))
6✔
71
        cmd.AddCommand(NewCloudCmd(out))
6✔
72

6✔
73
        return cmd
6✔
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc