本文整理汇总了Golang中github.com/juju/juju/cmd/envcmd.WriteCurrentEnvironment函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteCurrentEnvironment函数的具体用法?Golang WriteCurrentEnvironment怎么用?Golang WriteCurrentEnvironment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WriteCurrentEnvironment函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWriteAddsNewline
func (s *EnvironmentCommandSuite) TestWriteAddsNewline(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
current, err := ioutil.ReadFile(envcmd.GetCurrentEnvironmentFilePath())
c.Assert(err, gc.IsNil)
c.Assert(string(current), gc.Equals, "fubar\n")
}
开发者ID:klyachin,项目名称:juju,代码行数:7,代码来源:environmentcommand_test.go
示例2: TestGetDefaultEnvironmentCurrentEnvironmentSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentCurrentEnvironmentSet(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "fubar")
c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:7,代码来源:environmentcommand_test.go
示例3: SetUpTest
func (s *createSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
s.SetFeatureFlags(feature.JES)
s.fake = &fakeCreateClient{}
store := configstore.Default
s.AddCleanup(func(*gc.C) {
configstore.Default = store
})
s.store = configstore.NewMem()
configstore.Default = func() (configstore.Storage, error) {
return s.store, nil
}
// Set up the current environment, and write just enough info
// so we don't try to refresh
envName := "test-master"
s.serverUUID = "fake-server-uuid"
info := s.store.CreateInfo(envName)
info.SetAPIEndpoint(configstore.APIEndpoint{
Addresses: []string{"localhost"},
CACert: testing.CACert,
EnvironUUID: s.serverUUID,
ServerUUID: s.serverUUID,
})
info.SetAPICredentials(configstore.APICredentials{User: "bob", Password: "sekrit"})
err := info.Write()
c.Assert(err, jc.ErrorIsNil)
s.server = info
err = envcmd.WriteCurrentEnvironment(envName)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:30,代码来源:create_test.go
示例4: TestCurrentEnvironmentHasPrecedence
func (s *SwitchSimpleSuite) TestCurrentEnvironmentHasPrecedence(c *gc.C) {
testing.WriteEnvironments(c, testing.MultipleEnvConfig)
envcmd.WriteCurrentEnvironment("fubar")
context, err := testing.RunCommand(c, newSwitchCommand())
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), gc.Equals, "fubar\n")
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:switch_test.go
示例5: TestWriteControllerRemovesEnvironmentFile
func (s *filesSuite) TestWriteControllerRemovesEnvironmentFile(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
err = envcmd.WriteCurrentController("baz")
c.Assert(err, jc.ErrorIsNil)
c.Assert(envcmd.GetCurrentEnvironmentFilePath(), jc.DoesNotExist)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:files_test.go
示例6: TestGetDefaultEnvironmentBothSet
func (s *EnvironmentCommandSuite) TestGetDefaultEnvironmentBothSet(c *gc.C) {
os.Setenv(osenv.JujuEnvEnvKey, "magic")
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
env, err := envcmd.GetDefaultEnvironment()
c.Assert(env, gc.Equals, "magic")
c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:8,代码来源:environmentcommand_test.go
示例7: TestCurrentCommenctionNameEnvironment
func (*filesSuite) TestCurrentCommenctionNameEnvironment(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
name, isController, err := envcmd.CurrentConnectionName()
c.Assert(err, jc.ErrorIsNil)
c.Assert(isController, jc.IsFalse)
c.Assert(name, gc.Equals, "fubar")
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:files_test.go
示例8: TestSetCurrentControllerExistingEnv
func (s *filesSuite) TestSetCurrentControllerExistingEnv(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
ctx := testing.Context(c)
err = envcmd.SetCurrentController(ctx, "new-sys")
c.Assert(err, jc.ErrorIsNil)
s.assertCurrentController(c, "new-sys")
c.Assert(testing.Stderr(ctx), gc.Equals, "fubar -> new-sys (controller)\n")
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:files_test.go
示例9: switchEnvironment
// switchEnvironment changes the default environment to the given name and
// return, if set, the current default environment name.
func switchEnvironment(envName string) (string, error) {
if defaultEnv := os.Getenv(osenv.JujuEnvEnvKey); defaultEnv != "" {
return "", errors.Errorf("cannot switch when %s is overriding the environment (set to %q)", osenv.JujuEnvEnvKey, defaultEnv)
}
currentEnv, err := envcmd.GetDefaultEnvironment()
if err != nil {
return "", errors.Annotate(err, "cannot get the default environment")
}
if err := envcmd.WriteCurrentEnvironment(envName); err != nil {
return "", errors.Trace(err)
}
return currentEnv, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:15,代码来源:jenv.go
示例10: TestEnvironCommandInit
func (s *EnvironmentCommandSuite) TestEnvironCommandInit(c *gc.C) {
// Take environment name from command line arg.
testEnsureEnvName(c, "explicit", "-e", "explicit")
// Take environment name from the default.
coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfig)
testEnsureEnvName(c, coretesting.SampleEnvName)
// Take environment name from the one and only environment,
// even if it is not explicitly marked as default.
coretesting.WriteEnvironments(c, coretesting.SingleEnvConfigNoDefault)
testEnsureEnvName(c, coretesting.SampleEnvName)
// If there is a current-environment file, use that.
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
testEnsureEnvName(c, "fubar")
}
开发者ID:klyachin,项目名称:juju,代码行数:18,代码来源:environmentcommand_test.go
示例11: TestErrorWritingFile
func (*EnvironmentCommandSuite) TestErrorWritingFile(c *gc.C) {
// Can't write a file over a directory.
os.MkdirAll(envcmd.GetCurrentEnvironmentFilePath(), 0777)
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.ErrorMatches, "unable to write to the environment file: .*")
}
开发者ID:klyachin,项目名称:juju,代码行数:6,代码来源:environmentcommand_test.go
示例12: TestSystemCommandInitEnvFile
func (s *SystemCommandSuite) TestSystemCommandInitEnvFile(c *gc.C) {
// If there is a current-environment file, use that.
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
testEnsureSystemName(c, "fubar")
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:6,代码来源:systemcommand_test.go
示例13: TestReadCurrentEnvironmentSet
func (s *EnvironmentCommandSuite) TestReadCurrentEnvironmentSet(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
env := envcmd.ReadCurrentEnvironment()
c.Assert(env, gc.Equals, "fubar")
}
开发者ID:Pankov404,项目名称:juju,代码行数:6,代码来源:environmentcommand_test.go
示例14: TestReadCurrentEnvironmentSet
func (s *filesSuite) TestReadCurrentEnvironmentSet(c *gc.C) {
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, jc.ErrorIsNil)
s.assertCurrentEnvironment(c, "fubar")
}
开发者ID:imoapps,项目名称:juju,代码行数:5,代码来源:files_test.go
示例15: TestEnvironCommandInitEnvFile
func (s *EnvironmentCommandSuite) TestEnvironCommandInitEnvFile(c *gc.C) {
// If there is a current-environment file, use that.
err := envcmd.WriteCurrentEnvironment("fubar")
c.Assert(err, gc.IsNil)
testEnsureEnvName(c, "fubar")
}
开发者ID:kapilt,项目名称:juju,代码行数:6,代码来源:environmentcommand_test.go
示例16: Run
func (c *SwitchCommand) Run(ctx *cmd.Context) error {
// Switch is an alternative way of dealing with environments than using
// the JUJU_ENV environment setting, and as such, doesn't play too well.
// If JUJU_ENV is set we should report that as the current environment,
// and not allow switching when it is set.
// Passing through the empty string reads the default environments.yaml file.
environments, err := environs.ReadEnvirons("")
if err != nil {
return errors.New("couldn't read the environment")
}
names := environments.Names()
sort.Strings(names)
if c.List {
// List all environments.
if c.EnvName != "" {
return errors.New("cannot switch and list at the same time")
}
for _, name := range names {
fmt.Fprintf(ctx.Stdout, "%s\n", name)
}
return nil
}
jujuEnv := os.Getenv("JUJU_ENV")
if jujuEnv != "" {
if c.EnvName == "" {
fmt.Fprintf(ctx.Stdout, "%s\n", jujuEnv)
return nil
} else {
return fmt.Errorf("cannot switch when JUJU_ENV is overriding the environment (set to %q)", jujuEnv)
}
}
currentEnv := envcmd.ReadCurrentEnvironment()
if currentEnv == "" {
currentEnv = environments.Default
}
// Handle the different operation modes.
switch {
case c.EnvName == "" && currentEnv == "":
// Nothing specified and nothing to switch to.
return errors.New("no currently specified environment")
case c.EnvName == "":
// Simply print the current environment.
fmt.Fprintf(ctx.Stdout, "%s\n", currentEnv)
default:
// Switch the environment.
if !validEnvironmentName(c.EnvName, names) {
return fmt.Errorf("%q is not a name of an existing defined environment", c.EnvName)
}
if err := envcmd.WriteCurrentEnvironment(c.EnvName); err != nil {
return err
}
if currentEnv == "" {
fmt.Fprintf(ctx.Stdout, "-> %s\n", c.EnvName)
} else {
fmt.Fprintf(ctx.Stdout, "%s -> %s\n", currentEnv, c.EnvName)
}
}
return nil
}
开发者ID:jiasir,项目名称:juju,代码行数:64,代码来源:switch.go
示例17: SetUpTest
func (s *UserSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
envcmd.WriteCurrentEnvironment("dummyenv")
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:4,代码来源:cmd_juju_user_test.go
注:本文中的github.com/juju/juju/cmd/envcmd.WriteCurrentEnvironment函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论