github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/tag.go (about) 1 // Copyright (C) 2015 Scaleway. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE.md file. 4 5 package commands 6 7 import ( 8 "fmt" 9 10 "github.com/moul/anonuuid" 11 ) 12 13 // TagArgs are flags for the `RunTag` function 14 type TagArgs struct { 15 Snapshot string 16 Bootscript string 17 Name string 18 Arch string 19 } 20 21 // RunTag is the handler for 'scw tag' 22 func RunTag(ctx CommandContext, args TagArgs) error { 23 snapshotID, err := ctx.API.GetSnapshotID(args.Snapshot) 24 if err != nil { 25 return err 26 } 27 snapshot, err := ctx.API.GetSnapshot(snapshotID) 28 if err != nil { 29 return fmt.Errorf("cannot fetch snapshot: %v", err) 30 } 31 32 bootscriptID := "" 33 if args.Bootscript != "" { 34 if anonuuid.IsUUID(args.Bootscript) == nil { 35 bootscriptID = args.Bootscript 36 } else { 37 bootscriptID, err = ctx.API.GetBootscriptID(args.Bootscript, args.Arch) 38 if err != nil { 39 return err 40 } 41 } 42 } 43 image, err := ctx.API.PostImage(snapshot.Identifier, args.Name, bootscriptID, args.Arch) 44 if err != nil { 45 return fmt.Errorf("cannot create image: %v", err) 46 } 47 fmt.Fprintln(ctx.Stdout, image) 48 return nil 49 }