github.com/vanadium-archive/go.jiri@v0.0.0-20160715023856-abfb8b131290/profiles/profilesreader/flags.go (about)

     1  // Copyright 2015 The Vanadium Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package profilesreader
     6  
     7  import (
     8  	"flag"
     9  	"path/filepath"
    10  
    11  	"v.io/jiri"
    12  )
    13  
    14  // RegisterReaderFlags registers the flags commonly used with a profiles.Reader.
    15  // --profiles-manifest, --skip-profiles, --profiles and --merge-policies.
    16  func RegisterReaderFlags(flags *flag.FlagSet, profilesMode *ProfilesMode, manifest, profiles *string, defaultManifest string, policies *MergePolicies) {
    17  	flags.Var(profilesMode, "skip-profiles", "if set, no profiles will be used")
    18  	registerProfilesFlag(flags, profiles)
    19  	registerMergePoliciesFlag(flags, policies)
    20  	registerManifestFlag(flags, manifest, defaultManifest)
    21  }
    22  
    23  // RegisterProfilesFlag registers the --profiles flag
    24  func registerProfilesFlag(flags *flag.FlagSet, profiles *string) {
    25  	flags.StringVar(profiles, "profiles", "base,jiri", "a comma separated list of profiles to use")
    26  }
    27  
    28  // RegisterMergePoliciesFlag registers the --merge-policies flag
    29  func registerMergePoliciesFlag(flags *flag.FlagSet, policies *MergePolicies) {
    30  	flags.Var(policies, "merge-policies", "specify policies for merging environment variables")
    31  }
    32  
    33  // RegisterManifestFlag registers the commonly used --profiles-manifest
    34  // flag with the supplied FlagSet.
    35  func registerManifestFlag(flags *flag.FlagSet, manifest *string, defaultManifest string) {
    36  	root := jiri.FindRoot()
    37  	flags.StringVar(manifest, "profiles-manifest", filepath.Join(root, defaultManifest), "specify the profiles XML manifest filename.")
    38  	flags.Lookup("profiles-manifest").DefValue = filepath.Join("$JIRI_ROOT", defaultManifest)
    39  }