Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cli/cmd/auth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"fmt"

"github.com/nitrictech/nitric/cli/internal/version"
"github.com/nitrictech/nitric/cli/pkg/app"
"github.com/samber/do/v2"
"github.com/spf13/cobra"
Expand All @@ -10,8 +13,8 @@ import (
func NewLoginCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "login",
Short: "Login to Nitric",
Long: `Login to the Nitric CLI.`,
Short: fmt.Sprintf("Login to %s", version.ProductName),
Long: fmt.Sprintf("Login to the %s CLI.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.AuthApp](injector)
if err != nil {
Expand All @@ -26,8 +29,8 @@ func NewLoginCmd(injector do.Injector) *cobra.Command {
func NewLogoutCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "logout",
Short: "Logout from Nitric",
Long: `Logout from the Nitric CLI.`,
Short: fmt.Sprintf("Logout from %s", version.ProductName),
Long: fmt.Sprintf("Logout from the %s CLI.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.AuthApp](injector)
if err != nil {
Expand Down
25 changes: 14 additions & 11 deletions cli/cmd/nitric.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"fmt"

"github.com/nitrictech/nitric/cli/internal/version"
"github.com/nitrictech/nitric/cli/pkg/app"
"github.com/samber/do/v2"
"github.com/spf13/cobra"
Expand All @@ -26,8 +29,8 @@ func NewTemplatesCmd(injector do.Injector) *cobra.Command {
func NewInitCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "init",
Short: "Setup a new Nitric project",
Long: `Setup a new Nitric project, including within existing applications`,
Short: fmt.Sprintf("Setup a new %s project", version.ProductName),
Long: fmt.Sprintf("Setup a new %s project, including within existing applications", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.NitricApp](injector)
if err != nil {
Expand All @@ -44,8 +47,8 @@ func NewNewCmd(injector do.Injector) *cobra.Command {

cmd := &cobra.Command{
Use: "new [project-name]",
Short: "Create a new Nitric project",
Long: `Create a new Nitric project from a template.`,
Short: fmt.Sprintf("Create a new %s project", version.ProductName),
Long: fmt.Sprintf("Create a new %s project from a template.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
projectName := ""
if len(args) > 0 {
Expand All @@ -67,8 +70,8 @@ func NewNewCmd(injector do.Injector) *cobra.Command {
func NewBuildCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "build",
Short: "Builds the nitric application",
Long: `Builds an application using the nitric.yaml application spec and referenced platform.`,
Short: fmt.Sprintf("Builds the %s application", version.ProductName),
Long: "Builds an application using the nitric.yaml application spec and referenced platform.",
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.NitricApp](injector)
if err != nil {
Expand All @@ -88,8 +91,8 @@ func NewGenerateCmd(injector do.Injector) *cobra.Command {

cmd := &cobra.Command{
Use: "generate",
Short: "Generate client libraries",
Long: `Generate client libraries for different programming languages based on the Nitric application specification.`,
Short: fmt.Sprintf("Generate client libraries for %s", version.ProductName),
Long: fmt.Sprintf("Generate client libraries for different programming languages based on the %s application specification.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.NitricApp](injector)
if err != nil {
Expand Down Expand Up @@ -120,7 +123,7 @@ func NewGenerateCmd(injector do.Injector) *cobra.Command {
func NewEditCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "edit",
Short: "Edit the nitric application",
Short: fmt.Sprintf("Edit the %s application", version.ProductName),
Long: `Edits an application using the nitric.yaml application spec and referenced platform.`,
Run: func(cmd *cobra.Command, args []string) {
app, err := do.Invoke[*app.NitricApp](injector)
Expand All @@ -136,8 +139,8 @@ func NewEditCmd(injector do.Injector) *cobra.Command {
func NewDevCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "dev",
Short: "Run the Nitric application in development mode",
Long: `Run the Nitric application in development mode, allowing local testing of resources.`,
Short: fmt.Sprintf("Run the %s application in development mode", version.ProductName),
Long: fmt.Sprintf("Run the %s application in development mode, allowing local testing of resources.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
cobra.CheckErr(app.Dev())
},
Expand Down
12 changes: 5 additions & 7 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
func NewRootCmd(injector do.Injector) *cobra.Command {
rootCmd := &cobra.Command{
Use: "nitric",
Short: "Nitric CLI - The command line interface for Nitric",
Long: `Nitric CLI is a command line interface for managing and deploying
Nitric applications. It provides a set of commands to help you develop,
test, and deploy your Nitric applications.`,
Short: fmt.Sprintf("%s CLI - The command line interface for %s", version.ProductName, version.ProductName),
Long: fmt.Sprintf("%s CLI is a command line interface for managing and deploying %s applications. It provides a set of commands to help you develop, test, and deploy your %s applications.", version.ProductName, version.ProductName, version.ProductName),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.Load(cmd)
if err != nil {
Expand Down Expand Up @@ -49,11 +47,11 @@ test, and deploy your Nitric applications.`,
func NewVersionCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print the CLI version",
Long: `Display the version number of the Nitric CLI.`,
Short: fmt.Sprintf("Print the %s CLI version", version.ProductName),
Long: fmt.Sprintf("Display the version number of the %s CLI.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
highlight := lipgloss.NewStyle().Foreground(lipgloss.Color("14"))
fmt.Printf("nitric cli version %s\n", highlight.Render(version.Version))
fmt.Printf("%s cli version %s\n", version.ProductName, highlight.Render(version.Version))
},
}
}
7 changes: 4 additions & 3 deletions cli/internal/api/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"

"github.com/nitrictech/nitric/cli/internal/version"
"github.com/nitrictech/nitric/engines/terraform"
)

Expand All @@ -24,18 +25,18 @@ func (c *NitricApiClient) GetPlatform(team, name string, revision int) (*terrafo
return nil, ErrNotFound
}

return nil, fmt.Errorf("received non 200 response from nitric plugin details endpoint: %d", response.StatusCode)
return nil, fmt.Errorf("received non 200 response from %s plugin details endpoint: %d", version.ProductName, response.StatusCode)
}

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response from nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("failed to read response from %s plugin details endpoint: %v", version.ProductName, err)
}

var platformSpec PlatformRevisionResponse
err = json.Unmarshal(body, &platformSpec)
if err != nil {
return nil, fmt.Errorf("unexpected response from nitric plugin details endpoint: %v", err)
return nil, fmt.Errorf("unexpected response from %s plugin details endpoint: %v", version.ProductName, err)
}
return &platformSpec.Content, nil
}
15 changes: 8 additions & 7 deletions cli/internal/api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@ import (
"fmt"
"io"

"github.com/nitrictech/nitric/cli/internal/version"
"github.com/nitrictech/nitric/engines/terraform"
)

// FIXME: Because of the difference in fields between identity and resource plugins we need to return an interface
func (c *NitricApiClient) GetPluginManifest(team, lib, version, name string) (interface{}, error) {
response, err := c.get(fmt.Sprintf("/api/plugin_libraries/%s/%s/versions/%s/plugins/%s", team, lib, version, name), true)
func (c *NitricApiClient) GetPluginManifest(team, lib, libVersion, name string) (interface{}, error) {
response, err := c.get(fmt.Sprintf("/api/plugin_libraries/%s/%s/versions/%s/plugins/%s", team, lib, libVersion, name), true)
if err != nil {
return nil, fmt.Errorf("failed to connect to nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("failed to connect to %s plugin details endpoint: %v", version.ProductName, err)
}

if response.StatusCode != 200 {
return nil, fmt.Errorf("received non 200 response from nitric plugin details endpoint: %d", response.StatusCode)
return nil, fmt.Errorf("received non 200 response from %s plugin details endpoint: %d", version.ProductName, response.StatusCode)
}

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response from nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("failed to read response from %s plugin details endpoint: %v", version.ProductName, err)
}

var pluginManifest terraform.ResourcePluginManifest
err = json.Unmarshal(body, &pluginManifest)
if err != nil {
return nil, fmt.Errorf("unexpected response from nitric plugin details endpoint: %v", err)
return nil, fmt.Errorf("unexpected response from %s plugin details endpoint: %v", version.ProductName, err)
}

if pluginManifest.Type == "identity" {
var identityPluginManifest terraform.IdentityPluginManifest
err = json.Unmarshal(body, &identityPluginManifest)
if err != nil {
return nil, fmt.Errorf("unexpected response from nitric plugin details endpoint: %v", err)
return nil, fmt.Errorf("unexpected response from %s plugin details endpoint: %v", version.ProductName, err)
}

return &identityPluginManifest, nil
Expand Down
3 changes: 2 additions & 1 deletion cli/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/mitchellh/mapstructure"
"github.com/nitrictech/nitric/cli/internal/version"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *Config) SetValue(key, value string) error {
func (c *Config) GetNitricServerUrl() *url.URL {
nitricUrl, err := url.Parse(c.NitricServerUrl)
if err != nil {
fmt.Printf("Error parsing nitric server url from config, using default: %v\n", err)
fmt.Printf("Error parsing %s server url from config, using default: %v\n", version.ProductName, err)
return &url.URL{
Scheme: "https",
Host: "app.nitric.io",
Expand Down
9 changes: 5 additions & 4 deletions cli/internal/details/service/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/nitrictech/nitric/cli/internal/config"
detail "github.com/nitrictech/nitric/cli/internal/details"
"github.com/nitrictech/nitric/cli/internal/version"
"github.com/samber/do/v2"
)

Expand Down Expand Up @@ -45,20 +46,20 @@ func (s *Service) GetWorkOSDetails() (*detail.WorkOSDetails, error) {
response, err := http.DefaultClient.Do(req)
if err != nil {
if strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "connection reset by peer") {
return nil, fmt.Errorf("failed to connect to the Nitric API. Please check your connection and try again. If the problem persists, please contact support.")
return nil, fmt.Errorf("failed to connect to the %s API. Please check your connection and try again. If the problem persists, please contact support.", version.ProductName)
}
return nil, fmt.Errorf("failed to connect to nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("failed to connect to %s auth details endpoint: %v", version.ProductName, err)
}

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response from nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("failed to read response from %s auth details endpoint: %v", version.ProductName, err)
}

var authDetails AuthDetails
err = json.Unmarshal(body, &authDetails)
if err != nil {
return nil, fmt.Errorf("unexpected response from nitric auth details endpoint: %v", err)
return nil, fmt.Errorf("unexpected response from %s auth details endpoint: %v", version.ProductName, err)
}

return &authDetails.WorkOS, nil
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type SimulationServer struct {

const DEFAULT_SERVER_PORT = "50051"

var nitric = style.Purple(icons.Lightning + " Nitric")
var nitric = style.Purple(icons.Lightning + " " + version.ProductName)

func nitricIntro(addr string, dashUrl string, appSpec *schema.Application) string {
version := version.GetShortVersion()
Expand Down
102 changes: 101 additions & 1 deletion cli/internal/style/colors/colors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package colors

import "github.com/charmbracelet/lipgloss"
import (
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/nitrictech/nitric/cli/internal/style/icons"
)

//

Expand Down Expand Up @@ -48,3 +52,99 @@ var (
// Dark: AdaptiveBlue,
// }
// )

var Theme = huh.Theme{
Form: huh.FormStyles{
Base: lipgloss.NewStyle(),
},
Group: huh.GroupStyles{
Base: lipgloss.NewStyle(),
Title: lipgloss.NewStyle(),
Description: lipgloss.NewStyle(),
},
FieldSeparator: lipgloss.NewStyle(),
Blurred: huh.FieldStyles{
Base: lipgloss.NewStyle(),
Title: lipgloss.NewStyle().Faint(true),
Description: lipgloss.NewStyle().Faint(true),
ErrorIndicator: lipgloss.NewStyle(),
ErrorMessage: lipgloss.NewStyle(),

// Select styles.
SelectSelector: lipgloss.NewStyle(), // Selection indicator
Option: lipgloss.NewStyle(), // Select options
NextIndicator: lipgloss.NewStyle(),
PrevIndicator: lipgloss.NewStyle(),

// FilePicker styles.
Directory: lipgloss.NewStyle(),
File: lipgloss.NewStyle(),

// Multi-select styles.
MultiSelectSelector: lipgloss.NewStyle(),
SelectedOption: lipgloss.NewStyle(),
SelectedPrefix: lipgloss.NewStyle(),
UnselectedOption: lipgloss.NewStyle(),
UnselectedPrefix: lipgloss.NewStyle(),

// Textinput and teatarea styles.
TextInput: huh.TextInputStyles{
Cursor: lipgloss.NewStyle(),
CursorText: lipgloss.NewStyle(),
Placeholder: lipgloss.NewStyle(),
Prompt: lipgloss.NewStyle(),
Text: lipgloss.NewStyle(),
},

// Confirm styles.
FocusedButton: lipgloss.NewStyle(),
BlurredButton: lipgloss.NewStyle(),

// Card styles.
Card: lipgloss.NewStyle(),
NoteTitle: lipgloss.NewStyle(),
Next: lipgloss.NewStyle(),
},
Focused: huh.FieldStyles{
Base: lipgloss.NewStyle(),
Title: lipgloss.NewStyle().Foreground(Teal).Bold(true),
Description: lipgloss.NewStyle().Faint(true),
ErrorIndicator: lipgloss.NewStyle(),
ErrorMessage: lipgloss.NewStyle(),

// Select styles.
SelectSelector: lipgloss.NewStyle().SetString(icons.RightArrow + " ").Foreground(Teal).Bold(true), // Selection indicator
Option: lipgloss.NewStyle(), // Select options
NextIndicator: lipgloss.NewStyle(),
PrevIndicator: lipgloss.NewStyle(),

// FilePicker styles.
Directory: lipgloss.NewStyle(),
File: lipgloss.NewStyle(),

// Multi-select styles.
MultiSelectSelector: lipgloss.NewStyle(),
SelectedOption: lipgloss.NewStyle().Foreground(Teal).Bold(true),
SelectedPrefix: lipgloss.NewStyle().SetString(icons.RightArrow).Foreground(Teal).Bold(true),
UnselectedOption: lipgloss.NewStyle(),
UnselectedPrefix: lipgloss.NewStyle(),

// Textinput and teatarea styles.
TextInput: huh.TextInputStyles{
Cursor: lipgloss.NewStyle(),
CursorText: lipgloss.NewStyle(),
Placeholder: lipgloss.NewStyle(),
Prompt: lipgloss.NewStyle(),
Text: lipgloss.NewStyle(),
},

// Confirm styles.
FocusedButton: lipgloss.NewStyle(),
BlurredButton: lipgloss.NewStyle(),

// Card styles.
Card: lipgloss.NewStyle(),
NoteTitle: lipgloss.NewStyle(),
Next: lipgloss.NewStyle(),
},
}
Loading
Loading