deploy: Default --target to the first deployment target

This commit is contained in:
Robert van Gent 2019-05-31 10:10:38 -07:00 committed by Bjørn Erik Pedersen
parent 35abce27ca
commit 9df57154ee
3 changed files with 18 additions and 8 deletions

View file

@ -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("confirm", false, "ask for confirmation before making changes to the target")
cc.cmd.Flags().Bool("dryRun", false, "dry run") cc.cmd.Flags().Bool("dryRun", false, "dry run")
cc.cmd.Flags().Bool("force", false, "force upload of all files") cc.cmd.Flags().Bool("force", false, "force upload of all files")

View file

@ -77,8 +77,16 @@ func New(cfg config.Provider, localFs afero.Fs) (*Deployer, error) {
return nil, err return nil, err
} }
if len(dcfg.Targets) == 0 {
return nil, errors.New("no deployment targets found")
}
// Find the target to deploy to. // Find the target to deploy to.
var tgt *target var tgt *target
if targetName == "" {
// Default to the first target.
tgt = dcfg.Targets[0]
} else {
for _, t := range dcfg.Targets { for _, t := range dcfg.Targets {
if t.Name == targetName { if t.Name == targetName {
tgt = t tgt = t
@ -87,6 +95,7 @@ func New(cfg config.Provider, localFs afero.Fs) (*Deployer, error) {
if tgt == nil { if tgt == nil {
return nil, fmt.Errorf("deployment target %q not found", targetName) return nil, fmt.Errorf("deployment target %q not found", targetName)
} }
}
return &Deployer{ return &Deployer{
localFs: localFs, localFs: localFs,
target: tgt, target: tgt,
@ -105,6 +114,7 @@ func (d *Deployer) openBucket(ctx context.Context) (*blob.Bucket, error) {
if d.bucket != nil { if d.bucket != nil {
return 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) return blob.OpenBucket(ctx, d.target.URL)
} }

View file

@ -100,7 +100,7 @@ gzip = true
To deploy to a target: 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 Hugo will identify and apply any local changes that need to be reflected to the