Skip to content

Commit

Permalink
Project skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Dec 19, 2018
1 parent d823392 commit d91e5c4
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/odm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright © 2018 CloudODM Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import "github.com/OpenDroneMap/CloudODM/internal/cmd"

func main() {
cmd.Execute()
}
45 changes: 45 additions & 0 deletions internal/cmd/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright © 2018 CloudODM Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// nodeCmd represents the node command
var nodeCmd = &cobra.Command{
Use: "node",
Short: "Manage processing nodes",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("node called")
},
}

func init() {
rootCmd.AddCommand(nodeCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// nodeCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// nodeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
88 changes: 88 additions & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright © 2018 CloudODM Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"fmt"
"os"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string

var rootCmd = &cobra.Command{
Use: "odm",
Short: "A command line tool to process aerial imagery in the cloud",

Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("TODO: %v\n", args)
},

TraverseChildren: true,

FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: true,
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.odm.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Search config in home directory with name ".odm" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".odm")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
41 changes: 41 additions & 0 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright © 2018 CloudODM Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var runCmd = &cobra.Command{
Use: "run",
Short: "Process a dataset",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("run called")
fmt.Println(os.Args[2:])
fmt.Println(args)
},

FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: true,
},
}

func init() {
rootCmd.AddCommand(runCmd)
}

0 comments on commit d91e5c4

Please sign in to comment.