Skip to content

Commit

Permalink
deploy: Default --target to the first deployment target
Browse files Browse the repository at this point in the history
  • Loading branch information
vangent authored and bep committed Jun 7, 2019
1 parent 35abce2 commit 9df5715
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ documentation.
},
})

cc.cmd.Flags().String("target", "default", "target deployment from deployments section in config file")
cc.cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one")
cc.cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
cc.cmd.Flags().Bool("dryRun", false, "dry run")
cc.cmd.Flags().Bool("force", false, "force upload of all files")
Expand Down
22 changes: 16 additions & 6 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,24 @@ func New(cfg config.Provider, localFs afero.Fs) (*Deployer, error) {
return nil, err
}

if len(dcfg.Targets) == 0 {
return nil, errors.New("no deployment targets found")
}

// Find the target to deploy to.
var tgt *target
for _, t := range dcfg.Targets {
if t.Name == targetName {
tgt = t
if targetName == "" {
// Default to the first target.
tgt = dcfg.Targets[0]
} else {
for _, t := range dcfg.Targets {
if t.Name == targetName {
tgt = t
}
}
if tgt == nil {
return nil, fmt.Errorf("deployment target %q not found", targetName)
}
}
if tgt == nil {
return nil, fmt.Errorf("deployment target %q not found", targetName)
}
return &Deployer{
localFs: localFs,
Expand All @@ -105,6 +114,7 @@ func (d *Deployer) openBucket(ctx context.Context) (*blob.Bucket, error) {
if d.bucket != nil {
return d.bucket, nil
}
jww.FEEDBACK.Printf("Deploying to target %q (%s)\n", d.target.Name, d.target.URL)
return blob.OpenBucket(ctx, d.target.URL)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/hosting-and-deployment/hugo-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ gzip = true

To deploy to a target:
```
hugo deploy --target=<target name>
hugo deploy [--target=<target name>, defaults to first target]
```

Hugo will identify and apply any local changes that need to be reflected to the
Expand Down

0 comments on commit 9df5715

Please sign in to comment.