mirror of
https://github.com/neilotoole/sq.git
synced 2025-01-01 21:03:23 +03:00
mostly tidyup
This commit is contained in:
parent
cce4196fe4
commit
0190eeaf70
2
Makefile
2
Makefile
@ -2,7 +2,7 @@
|
||||
# http://github.com/neilotoole/sq
|
||||
|
||||
BINARY := sq
|
||||
BUILD_VERSION=0.41.6
|
||||
BUILD_VERSION=0.41.7
|
||||
BUILD_TIMESTAMP := $(shell date +'%FT%T%z')
|
||||
|
||||
# SOURCES is the .go files for the project, excluding test files
|
||||
|
@ -30,7 +30,7 @@ This includes traditional SQL-style databases, or document formats such as JSON,
|
||||
> `sq` defines its own query language, seen above, formally known as `SLQ`.
|
||||
|
||||
|
||||
For usage information or to download the binary, see the `sq` [manual](https://github.com/neilotoole/sq-manual/wiki).
|
||||
For usage information or to download the binaries, see the `sq` [manual](https://github.com/neilotoole/sq-manual/wiki).
|
||||
|
||||
|
||||
## Development
|
||||
|
@ -69,7 +69,7 @@ func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _build_timestampTxt = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x32\x32\x30\x34\xd3\x35\x34\xd0\x35\x32\x0c\x31\x34\xb1\x32\x35\xb3\x32\x35\xd6\x35\x30\x33\x30\xe0\x02\x04\x00\x00\xff\xff\xab\x6f\xa1\x5e\x19\x00\x00\x00")
|
||||
var _build_timestampTxt = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x32\x32\x30\x34\xd3\x35\x34\xd0\x35\x32\x0c\x31\x32\xb0\x32\x35\xb3\x32\x36\xd7\x35\x30\x33\x30\xe0\x02\x04\x00\x00\xff\xff\x72\x0d\x59\xd0\x19\x00\x00\x00")
|
||||
|
||||
func build_timestampTxtBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
@ -84,12 +84,12 @@ func build_timestampTxt() (*asset, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "build_timestamp.txt", size: 25, mode: os.FileMode(420), modTime: time.Unix(1477083413, 0)}
|
||||
info := bindataFileInfo{name: "build_timestamp.txt", size: 25, mode: os.FileMode(420), modTime: time.Unix(1477104997, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _build_versionTxt = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x32\xd0\x33\x31\xd4\x33\xe3\x02\x04\x00\x00\xff\xff\x69\x8c\x85\x4f\x07\x00\x00\x00")
|
||||
var _build_versionTxt = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x32\xd0\x33\x31\xd4\x33\xe7\x02\x04\x00\x00\xff\xff\x28\xbd\x9e\x56\x07\x00\x00\x00")
|
||||
|
||||
func build_versionTxtBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
@ -104,7 +104,7 @@ func build_versionTxt() (*asset, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "build_version.txt", size: 7, mode: os.FileMode(420), modTime: time.Unix(1477083413, 0)}
|
||||
info := bindataFileInfo{name: "build_version.txt", size: 7, mode: os.FileMode(420), modTime: time.Unix(1477104997, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -23,9 +23,6 @@ const FormatXML Format = "xml"
|
||||
const FormatCSV Format = "csv"
|
||||
const FormatTSV Format = "tsv"
|
||||
|
||||
var conf *Config
|
||||
var str Store
|
||||
|
||||
// Config holds application config/session data.
|
||||
type Config struct {
|
||||
cfgDir string
|
||||
@ -48,39 +45,6 @@ type Log struct {
|
||||
ExcludePkgs []string `yaml:"exclude_pkgs"`
|
||||
}
|
||||
|
||||
// TODO: need to add a file write lock
|
||||
|
||||
//// Default returns the default config singleton.
|
||||
//func Default() *Config {
|
||||
//
|
||||
// if conf == nil {
|
||||
//
|
||||
// if str == nil {
|
||||
// panic("config.Default() invoked before config.SetStore() ")
|
||||
// }
|
||||
//
|
||||
// cfg, err := str.Load()
|
||||
// if err != nil {
|
||||
// // TODO: should try to load before this
|
||||
// panic(err)
|
||||
// }
|
||||
// conf = cfg
|
||||
// }
|
||||
//
|
||||
// return conf
|
||||
//}
|
||||
|
||||
// SetStore specifies the store for config persistence.
|
||||
func SetStore(store Store) {
|
||||
str = store
|
||||
}
|
||||
|
||||
//// defaultPath returns ~/.sq/sq.yml
|
||||
//func defaultPath() (string, error) {
|
||||
//
|
||||
// return filepath.Join(util.ConfigDir(), "sq.yml"), nil
|
||||
//}
|
||||
|
||||
// New returns a config instance with default options set.
|
||||
func New() *Config {
|
||||
lg.Debugf("new config instance")
|
||||
@ -92,7 +56,6 @@ func New() *Config {
|
||||
|
||||
// applyDefaults checks if required values are present, and if not, sets them.
|
||||
func applyDefaults(cfg *Config) {
|
||||
lg.Debugf("checking that cfg has default values set")
|
||||
|
||||
if cfg.SourceSet == nil {
|
||||
cfg.SourceSet = drvr.NewSourceSet()
|
||||
|
@ -80,7 +80,7 @@ func (f *FileStore) Save(cfg *Config) error {
|
||||
}
|
||||
|
||||
// FileExists returns true if the backing file can be accessed, false if it doesn't
|
||||
// exist or any error.
|
||||
// exist or on any error.
|
||||
func (f *FileStore) FileExists() bool {
|
||||
_, err := os.Stat(f.Path)
|
||||
return err == nil
|
||||
@ -122,7 +122,6 @@ func (f *InMemoryStore) String() string {
|
||||
|
||||
// Load returns a new config
|
||||
func (f *InMemoryStore) Load() (*Config, error) {
|
||||
|
||||
return New(), nil
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ func initConfig(cmd *cobra.Command) (*config.Config, config.Store, error) {
|
||||
}
|
||||
|
||||
cfgStore = &config.FileStore{cfgPath}
|
||||
lg.Debugf("will use config file: %v", cfgStore.Path)
|
||||
lg.Debugf("attempting to use config file %q", cfgStore.Path)
|
||||
if !cfgStore.FileExists() {
|
||||
lg.Debugf("config file does not exist: %v", cfgStore.Path)
|
||||
cfg = config.New()
|
||||
@ -153,7 +153,7 @@ func initConfig(cmd *cobra.Command) (*config.Config, config.Store, error) {
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
lg.Debugf("loaded config from %q", cfgStore.Path)
|
||||
lg.Debugf("loaded config file %q", cfgStore.Path)
|
||||
cfg = conf
|
||||
return cfg, cfgStore, nil
|
||||
}
|
||||
@ -188,7 +188,7 @@ func preprocessCmd(cmd *cobra.Command) {
|
||||
// preExec is called before a cmd is executed.
|
||||
func preExec(cmd *cobra.Command, args []string) error {
|
||||
|
||||
lg.Debugf("preExec cmd %q: %v", cmd.Name(), args)
|
||||
lg.Debugf("executing command %q: %v", cmd.Name(), args)
|
||||
_, _, err := initConfig(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// Plan models a sq execution plan.
|
||||
// At this time Plan effectively models a query, but in future it will also model
|
||||
// At this time Plan effectively models just queries, but in future it will also model
|
||||
// operations such as copy/inserts etc.
|
||||
type Plan struct {
|
||||
AST *ast.AST
|
||||
@ -34,14 +34,13 @@ func NewPlanBuilder(srcs *drvr.SourceSet) *PlanBuilder {
|
||||
return &PlanBuilder{srcs: srcs}
|
||||
}
|
||||
|
||||
// Model builds a SelectStmt from the IR.
|
||||
// Build creates a Plan instance from the AST.
|
||||
func (pb *PlanBuilder) Build(a *ast.AST) (*Plan, error) {
|
||||
|
||||
lg.Debugf("starting to build model")
|
||||
lg.Debugf("building plan...")
|
||||
|
||||
lg.Debugf("starting build2()")
|
||||
if len(a.Segments()) == 0 {
|
||||
return nil, errorf("parse error: the query does not have enough segments")
|
||||
return nil, errorf("plan error: the query does not have enough segments")
|
||||
}
|
||||
|
||||
stmt := &Plan{AST: a}
|
||||
|
3
main.go
3
main.go
@ -12,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
str := "\n" + strings.Repeat("*", 80) + "\n > " + strings.Join(os.Args, " ") + "\n" + strings.Repeat("*", 80)
|
||||
lg.Debugf(str)
|
||||
|
||||
cmd.Execute()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user