Skip to content

Commit

Permalink
Basic globbing, command line parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Jan 4, 2019
1 parent 3bdafd7 commit a8f39bb
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var nodeCmd = &cobra.Command{
config.Initialize()

for k, n := range config.User.Nodes {
if logger.Verbose {
if logger.VerboseFlag {
logger.Info(k + " - " + n.String())
} else {
logger.Info(k)
Expand Down
56 changes: 52 additions & 4 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,39 @@ package cmd

import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/OpenDroneMap/CloudODM/internal/config"
"github.com/OpenDroneMap/CloudODM/internal/fs"
"github.com/OpenDroneMap/CloudODM/internal/logger"

"github.com/spf13/cobra"
)

var outputPath string

var rootCmd = &cobra.Command{
Use: "odm",
Use: "odm [flags] <images> [<gcp>] [parameters]",
Short: "A command line tool to process aerial imagery in the cloud",

Run: func(cmd *cobra.Command, args []string) {
config.Initialize()
if len(args) == 0 {
cmd.Help()
os.Exit(0)
}

inputFiles, options := parseArgs(args)

fmt.Printf("TODO: %v\n", args)
logger.Verbose("Input Files (" + strconv.Itoa(len(inputFiles)) + ")")
for _, file := range inputFiles {
logger.Debug(" * " + file)
}

logger.Debug("Options: " + strings.Join(options, " "))
},

TraverseChildren: true,
Expand All @@ -48,6 +66,36 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&logger.Verbose, "verbose", "v", false, "show verbose output")
rootCmd.PersistentFlags().BoolVar(&logger.Verbose, "debug", false, "show debug output")
rootCmd.PersistentFlags().BoolVarP(&logger.VerboseFlag, "verbose", "v", false, "show verbose output")
rootCmd.PersistentFlags().BoolVarP(&logger.DebugFlag, "debug", "d", false, "show debug output")
rootCmd.Flags().StringVarP(&outputPath, "output", "o", "./output", "directory where to store processing results")
rootCmd.Flags().SetInterspersed(false)
}

func parseArgs(args []string) ([]string, []string) {
var inputFiles []string
var options []string

for _, arg := range args {
if fs.IsDirectory(arg) {
// Add everything from directory
globPaths, err := filepath.Glob(arg + "/*")
if err != nil {
logger.Error(err)
}

for _, globPath := range globPaths {
if fs.IsFile(globPath) {
inputFiles = append(inputFiles, globPath)
}
}
} else if fs.IsFile(arg) {
fmt.Printf(arg)
inputFiles = append(inputFiles, arg)
} else {
options = append(options, arg)
}
}

return inputFiles, options
}
18 changes: 18 additions & 0 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@ func FileExists(filePath string) (bool, error) {

return exists, nil
}

// IsDirectory checks whether a path is a directory
func IsDirectory(path string) bool {
fileInfo, err := os.Stat(path)
if err != nil {
return false
}
return fileInfo.IsDir()
}

// IsFile checks whether a path is a directory
func IsFile(path string) bool {
fileInfo, err := os.Stat(path)
if err != nil {
return false
}
return !fileInfo.IsDir()
}
9 changes: 8 additions & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Verbose output
var Verbose bool
var VerboseFlag bool

// DebugFlag sets debug output
var DebugFlag bool
Expand All @@ -18,6 +18,13 @@ func Debug(a ...interface{}) {
}
}

// Verbose message (if VerboseFlag is enabled)
func Verbose(a ...interface{}) {
if VerboseFlag || DebugFlag {
fmt.Println(a...)
}
}

// Info message
func Info(a ...interface{}) {
fmt.Println(a...)
Expand Down
7 changes: 7 additions & 0 deletions internal/odm/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package odm

// Option is an option that can be passed to NodeODM
type Option struct {
Name string
Value interface{}
}
5 changes: 5 additions & 0 deletions internal/odm/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package odm

func Run(files []string, options []Option) {

}

0 comments on commit a8f39bb

Please sign in to comment.