Skip to content

Commit

Permalink
feat(qri-ref): Cleanup return values, use varName package
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Jul 11, 2019
1 parent 93c50c2 commit d3b8688
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/qri-io/dataset"
"github.com/qri-io/ioes"
"github.com/qri-io/qri/lib"
"github.com/qri-io/varName"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func (o *InitOptions) Run() (err error) {
if err != nil {
return err
}
suggestDataset := filepath.Base(pwd)
suggestDataset := varName.CreateVarNameFromString(filepath.Base(pwd))

// Process flags for inputs, prompt for any that were not provided.
var dsName, dsFormat string
Expand Down
2 changes: 1 addition & 1 deletion cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type SaveOptions struct {
// Complete adds any missing configuration that can only be added just before calling Run
func (o *SaveOptions) Complete(f Factory, args []string) (err error) {
o.Ref, err = GetDatasetRefString(f, args, 0)
o.IsLinkedRef, _ = GetLinkedFilesysRef()
_, o.IsLinkedRef = GetLinkedFilesysRef()

if o.IsLinkedRef {
// Determine format of the body.
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type StatusOptions struct {
// Complete adds any missing configuration that can only be added just before calling Run
func (o *StatusOptions) Complete(f Factory, args []string) (err error) {
var ok bool
ok, o.Selection = GetLinkedFilesysRef()
o.Selection, ok = GetLinkedFilesysRef()
if !ok {
return fmt.Errorf("this is not a linked working directory")
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/qri-io/ioes"
"github.com/qri-io/qri/lib"
Expand Down Expand Up @@ -138,7 +139,7 @@ func GetDatasetRefString(f Factory, args []string, index int) (string, error) {
return args[index], nil
}
// If in a working directory that is linked to a dataset, use that link's reference.
ok, data := GetLinkedFilesysRef()
data, ok := GetLinkedFilesysRef()
if ok {
return data, nil
}
Expand All @@ -156,12 +157,12 @@ func GetDatasetRefString(f Factory, args []string, index int) (string, error) {

// GetLinkedFilesysRef returns whether the current directory is linked to a dataset in your repo,
// and the reference to that dataset.
func GetLinkedFilesysRef() (bool, string) {
func GetLinkedFilesysRef() (string, bool) {
data, err := ioutil.ReadFile(QriRefFilename)
if err == nil {
return true, string(data)
return strings.TrimSpace(string(data)), true
}
return false, ""
return "", false
}

// DefaultSelectedRefList returns the list of currently selected dataset references
Expand Down

0 comments on commit d3b8688

Please sign in to comment.