github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/machine/flags.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package machine
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  
    10  	"github.com/juju/errors"
    11  
    12  	"github.com/juju/juju/storage"
    13  )
    14  
    15  type disksFlag struct {
    16  	disks *[]storage.Constraints
    17  }
    18  
    19  // Set implements gnuflag.Value.Set.
    20  func (f disksFlag) Set(s string) error {
    21  	for _, field := range strings.Fields(s) {
    22  		cons, err := storage.ParseConstraints(field)
    23  		if err != nil {
    24  			return errors.Annotate(err, "cannot parse disk constraints")
    25  		}
    26  		*f.disks = append(*f.disks, cons)
    27  	}
    28  	return nil
    29  }
    30  
    31  // Set implements gnuflag.Value.String.
    32  func (f disksFlag) String() string {
    33  	strs := make([]string, len(*f.disks))
    34  	for i, cons := range *f.disks {
    35  		strs[i] = fmt.Sprint(cons)
    36  	}
    37  	return strings.Join(strs, " ")
    38  }