Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Unified Diff: vpython/application/support.go

Issue 2705593003: vpython: Add application entry point. (Closed)
Patch Set: rebarse? Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vpython/application/subcommand_install.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vpython/application/support.go
diff --git a/vpython/application/support.go b/vpython/application/support.go
new file mode 100644
index 0000000000000000000000000000000000000000..87ac6b8dd6dcd9cde2ded310870e4d0bac042cbb
--- /dev/null
+++ b/vpython/application/support.go
@@ -0,0 +1,37 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package application
+
+import (
+ "github.com/luci/luci-go/common/errors"
+
+ "golang.org/x/net/context"
+)
+
+var appKey = "github.com/luci/luci-go/vpython/application.A"
+
+func withConfig(c context.Context, cfg *Config) context.Context {
+ return context.WithValue(c, &appKey, cfg)
+}
+
+func getConfig(c context.Context) *Config {
+ return c.Value(&appKey).(*Config)
+}
+
+func run(c context.Context, fn func(context.Context) error) int {
+ err := fn(c)
+
+ switch t := errors.Unwrap(err).(type) {
+ case nil:
+ return 0
+
+ case ReturnCodeError:
+ return int(t)
+
+ default:
+ errors.Log(c, err)
+ return 1
+ }
+}
« no previous file with comments | « vpython/application/subcommand_install.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698