From 53ca56c221be58a657a4173296f33be9eaa1f9e8 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 17:34:58 +0200 Subject: [PATCH] Separate update command into own file cmd/jb/update.go --- cmd/jb/main.go | 43 -------------------------------- cmd/jb/update.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 cmd/jb/update.go diff --git a/cmd/jb/main.go b/cmd/jb/main.go index e49103a..76e0016 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -15,18 +15,12 @@ package main import ( - "context" - "encoding/json" "fmt" - "io/ioutil" - "net/url" "os" "path" "path/filepath" "regexp" - "github.com/jsonnet-bundler/jsonnet-bundler/pkg" - "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/pkg/errors" "gopkg.in/alecthomas/kingpin.v2" @@ -217,40 +211,3 @@ func parseGithubDependency(urlString string) *spec.Dependency { Version: version, } } - -func updateCommand(jsonnetHome string, urls ...*url.URL) int { - m, err := pkg.LoadJsonnetfile(jsonnetfile.File) - if err != nil { - kingpin.Fatalf("failed to load jsonnetfile: %v", err) - return 1 - } - - err = os.MkdirAll(jsonnetHome, os.ModePerm) - if err != nil { - kingpin.Fatalf("failed to create jsonnet home path: %v", err) - return 3 - } - - // When updating, the lockfile is explicitly ignored. - isLock := false - lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome) - if err != nil { - kingpin.Fatalf("failed to install: %v", err) - return 3 - } - - b, err := json.MarshalIndent(lock, "", " ") - if err != nil { - kingpin.Fatalf("failed to encode jsonnet file: %v", err) - return 3 - } - b = append(b, []byte("\n")...) - - err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644) - if err != nil { - kingpin.Fatalf("failed to write lock file: %v", err) - return 3 - } - - return 0 -} diff --git a/cmd/jb/update.go b/cmd/jb/update.go new file mode 100644 index 0000000..9496d31 --- /dev/null +++ b/cmd/jb/update.go @@ -0,0 +1,64 @@ +// Copyright 2018 jsonnet-bundler authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/url" + "os" + + "github.com/jsonnet-bundler/jsonnet-bundler/pkg" + "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" + "gopkg.in/alecthomas/kingpin.v2" +) + +func updateCommand(jsonnetHome string, urls ...*url.URL) int { + m, err := pkg.LoadJsonnetfile(jsonnetfile.File) + if err != nil { + kingpin.Fatalf("failed to load jsonnetfile: %v", err) + return 1 + } + + err = os.MkdirAll(jsonnetHome, os.ModePerm) + if err != nil { + kingpin.Fatalf("failed to create jsonnet home path: %v", err) + return 3 + } + + // When updating, the lockfile is explicitly ignored. + isLock := false + lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome) + if err != nil { + kingpin.Fatalf("failed to install: %v", err) + return 3 + } + + b, err := json.MarshalIndent(lock, "", " ") + if err != nil { + kingpin.Fatalf("failed to encode jsonnet file: %v", err) + return 3 + } + b = append(b, []byte("\n")...) + + err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644) + if err != nil { + kingpin.Fatalf("failed to write lock file: %v", err) + return 3 + } + + return 0 +}