summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobert van Gent <[email protected]>2019-05-31 10:10:38 -0700
committerBjørn Erik Pedersen <[email protected]>2019-06-08 00:41:59 +0200
commit9df57154ee3e3185d024bfe376101b404d8b7cc4 (patch)
tree4b4c1f33f363a8c0c9712d295bcc632e71c8e28c
parent35abce27cabee43cc751db55a75b927f26275833 (diff)
downloadhugo-9df57154ee3e3185d024bfe376101b404d8b7cc4.tar.gz
hugo-9df57154ee3e3185d024bfe376101b404d8b7cc4.zip
deploy: Default --target to the first deployment target
-rw-r--r--commands/deploy.go2
-rw-r--r--deploy/deploy.go22
-rw-r--r--docs/content/en/hosting-and-deployment/hugo-deploy.md2
3 files changed, 18 insertions, 8 deletions
diff --git a/commands/deploy.go b/commands/deploy.go
index f9f369f4d..c3999427e 100644
--- a/commands/deploy.go
+++ b/commands/deploy.go
@@ -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")
diff --git a/deploy/deploy.go b/deploy/deploy.go
index e83410618..0512e352e 100644
--- a/deploy/deploy.go
+++ b/deploy/deploy.go
@@ -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,
@@ -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)
}
diff --git a/docs/content/en/hosting-and-deployment/hugo-deploy.md b/docs/content/en/hosting-and-deployment/hugo-deploy.md
index fa578a604..f8614b953 100644
--- a/docs/content/en/hosting-and-deployment/hugo-deploy.md
+++ b/docs/content/en/hosting-and-deployment/hugo-deploy.md
@@ -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