mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
Separate update command into own file cmd/jb/update.go
This commit is contained in:
parent
30a3cde870
commit
53ca56c221
2 changed files with 64 additions and 43 deletions
|
|
@ -15,18 +15,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"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/jsonnet-bundler/jsonnet-bundler/spec"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
|
@ -217,40 +211,3 @@ func parseGithubDependency(urlString string) *spec.Dependency {
|
||||||
Version: version,
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
64
cmd/jb/update.go
Normal file
64
cmd/jb/update.go
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue