github.com/Xenoex/gopm@v0.6.5/cmd/config.go (about) 1 // Copyright 2013-2014 gopm authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package cmd 16 17 import ( 18 "path" 19 20 "github.com/Unknwon/goconfig" 21 "github.com/codegangsta/cli" 22 23 "github.com/gpmgo/gopm/doc" 24 "github.com/gpmgo/gopm/log" 25 ) 26 27 var CmdConfig = cli.Command{ 28 Name: "config", 29 Usage: "configurate gopm global settings", 30 Description: `Command config configurates gopm global settings 31 32 gopm config github [client_id] [client_secret] 33 `, 34 Action: runConfig, 35 Flags: []cli.Flag{ 36 cli.BoolFlag{"verbose, v", "show process details"}, 37 }, 38 } 39 40 func runConfig(ctx *cli.Context) { 41 setup(ctx) 42 43 if len(ctx.Args()) == 0 { 44 log.Error("config", "Cannot start command:") 45 log.Fatal("", "\tNo section specified") 46 } 47 48 switch ctx.Args()[0] { 49 case "github": 50 if len(ctx.Args()) < 3 { 51 log.Error("config", "Cannot config section 'github'") 52 log.Fatal("", "\tNot enough arguments for client_id and client_secret") 53 } 54 doc.Cfg.SetValue("github", "client_id", ctx.Args()[1]) 55 doc.Cfg.SetValue("github", "client_secret", ctx.Args()[2]) 56 goconfig.SaveConfigFile(doc.Cfg, path.Join(doc.HomeDir, doc.GOPM_CONFIG_FILE)) 57 } 58 59 log.Success("SUCC", "config", "Command executed successfully!") 60 }