mirror of
https://github.com/coollabsio/coolify-cli.git
synced 2026-06-19 07:35:04 +00:00
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package application
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/coollabsio/coolify-cli/internal/cli"
|
|
"github.com/coollabsio/coolify-cli/internal/models"
|
|
"github.com/coollabsio/coolify-cli/internal/output"
|
|
"github.com/coollabsio/coolify-cli/internal/service"
|
|
)
|
|
|
|
func NewListCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all applications",
|
|
Long: `List all applications in Coolify.`,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
ctx := cmd.Context()
|
|
|
|
client, err := cli.GetAPIClient(cmd)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get API client: %w", err)
|
|
}
|
|
|
|
appSvc := service.NewApplicationService(client)
|
|
apps, err := appSvc.List(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to list applications: %w", err)
|
|
}
|
|
|
|
format, _ := cmd.Flags().GetString("format")
|
|
showSensitive, _ := cmd.Flags().GetBool("show-sensitive")
|
|
|
|
// For JSON/pretty formats, return the full application structure
|
|
if format != output.FormatTable {
|
|
formatter, err := output.NewFormatter(format, output.Options{
|
|
ShowSensitive: showSensitive,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return formatter.Format(apps)
|
|
}
|
|
|
|
// For table format, convert to simplified rows
|
|
var rows []models.ApplicationListItem
|
|
for _, app := range apps {
|
|
rows = append(rows, models.ApplicationListItem{
|
|
UUID: app.UUID,
|
|
Name: app.Name,
|
|
Description: app.Description,
|
|
Status: app.Status,
|
|
GitBranch: app.GitBranch,
|
|
FQDN: app.FQDN,
|
|
})
|
|
}
|
|
|
|
formatter, err := output.NewFormatter(format, output.Options{
|
|
ShowSensitive: showSensitive,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return formatter.Format(rows)
|
|
},
|
|
}
|
|
}
|