# Align trail create and phase handling with API

`1a6c8a5`→[main](/content/gh/entireio/cli/commits/main/index.html)·

dipree·1mo ago·5 files·+199 added/-84 removed

## Sessions

9a927e4dbff4View transcript

## Changes

5

- cmd/entire/cli

- api

- Mtrail_types.go-2

- Mtrail_cmd.go+107/-67

- Mtrail_cmd_test.go+89/-12

- Mtrail_watch_cmd.go+1/-1

- Mtrail_watch_cmd_test.go+2/-2

```go
    // trailListServerMaxLimit is the most trails the server returns per
    // request (the list endpoint clamps limit to 200).
    trailListServerMaxLimit = 200
    trailFindMaxPages       = 100
)

func newTrailCmd() *cobra.Command {
var title, body, base, branch, status, phase string
var title, body, base, branch, status string
var checkout bool

cmd := &cobra.Command{
    Short: "Create a trail for the current or a new branch",
    Args:  cobra.NoArgs,
    RunE: func(cmd *cobra.Command, _ []string) error {
        return runTrailCreate(cmd, title, body, base, branch, status, phase, checkout)
        return runTrailCreate(cmd, title, body, base, branch, status, checkout)
    },
}

//nolint:cyclop // sequential steps for creating a trail — splitting would obscure the flow
func runTrailCreate(cmd *cobra.Command, title, body, base, branch, statusStr, phase string, checkout bool) error { ... }

func newTrailUpdateCmd() *cobra.Command {
var statusStr, title, body, branch, phase string
var statusStr, title, body, branch string
var labelAdd, labelRemove []string

cmd := &cobra.Command{
   TitleChanged:  cmd.Flags().Changed("title"),
   Body:          body,
   BodyChanged:   cmd.Flags().Changed("body"),
   Phase:         phase,
   PhaseChanged:  cmd.Flags().Changed("phase"),
   Branch:        branch,
   LabelAdd:      labelAdd,
   LabelRemove:   labelRemove,
}

// ... Additional cmd declarations ...

func findTrail(ctx context.Context, client *api.Client, forge, owner, repo string, match func(api.TrailResource) bool) (*api.TrailResource, error) { ... }

func trailsBasePath(forge, owner, repo string) string { ... }

```

Mcmd/entire/cli/trail_cmd.go+107/-67

```go
// Function definitions, error handling, and other important logic here...

```

---

### Command Definitions

- `newTrailCmd()`: Defines a command to create a trail.
- `runTrailCreate(...)`: Handles creating a new trail with validations.
- `newTrailUpdateCmd()`: Sets up a command for updating an existing trail.
- `findTrail(...)`: Searches for existing trails based on criteria.
