github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/commands/deploy.go (about) 1 // Copyright 2019 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 // +build !nodeploy 15 16 package commands 17 18 import ( 19 "context" 20 21 "github.com/gohugoio/hugo/deploy" 22 "github.com/spf13/cobra" 23 ) 24 25 var _ cmder = (*deployCmd)(nil) 26 27 // deployCmd supports deploying sites to Cloud providers. 28 type deployCmd struct { 29 *baseBuilderCmd 30 31 invalidateCDN bool 32 maxDeletes int 33 } 34 35 // TODO: In addition to the "deploy" command, consider adding a "--deploy" 36 // flag for the default command; this would build the site and then deploy it. 37 // It's not obvious how to do this; would all of the deploy-specific flags 38 // have to exist at the top level as well? 39 40 // TODO: The output files change every time "hugo" is executed, it looks 41 // like because of map order randomization. This means that you can 42 // run "hugo && hugo deploy" again and again and upload new stuff every time. Is 43 // this intended? 44 45 func (b *commandsBuilder) newDeployCmd() *deployCmd { 46 cc := &deployCmd{} 47 48 cmd := &cobra.Command{ 49 Use: "deploy", 50 Short: "Deploy your site to a Cloud provider.", 51 Long: `Deploy your site to a Cloud provider. 52 53 See https://gohugo.io/hosting-and-deployment/hugo-deploy/ for detailed 54 documentation. 55 `, 56 57 RunE: func(cmd *cobra.Command, args []string) error { 58 cfgInit := func(c *commandeer) error { 59 c.Set("invalidateCDN", cc.invalidateCDN) 60 c.Set("maxDeletes", cc.maxDeletes) 61 return nil 62 } 63 comm, err := initializeConfig(true, true, false, &cc.hugoBuilderCommon, cc, cfgInit) 64 if err != nil { 65 return err 66 } 67 deployer, err := deploy.New(comm.Cfg, comm.hugo().PathSpec.PublishFs) 68 if err != nil { 69 return err 70 } 71 return deployer.Deploy(context.Background()) 72 }, 73 } 74 75 cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one") 76 cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target") 77 cmd.Flags().Bool("dryRun", false, "dry run") 78 cmd.Flags().Bool("force", false, "force upload of all files") 79 cmd.Flags().BoolVar(&cc.invalidateCDN, "invalidateCDN", true, "invalidate the CDN cache listed in the deployment target") 80 cmd.Flags().IntVar(&cc.maxDeletes, "maxDeletes", 256, "maximum # of files to delete, or -1 to disable") 81 82 cc.baseBuilderCmd = b.newBuilderBasicCmd(cmd) 83 84 return cc 85 }