Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nxy7 committed Jun 18, 2023
1 parent f553263 commit 4a72d20
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cmd/dev.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

Expand All @@ -13,7 +12,7 @@ import (
// devCmd represents the dev command
var devCmd = &cobra.Command{
Use: "dev",
Short: "A brief description of your command",
Short: "Start development of specific service",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Expand All @@ -27,7 +26,6 @@ to quickly create a Cobra application.`,

func init() {
rootCmd.AddCommand(devCmd)

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

// Cobra supports Persistent Flags which will work for this command
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"os"

"github.com/spf13/cobra"
"optimus/config"
)

var AppConfig config.Config

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "optimus",
Expand All @@ -19,6 +22,7 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {

err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand All @@ -28,5 +32,6 @@ func Execute() {
func init() {
// parse config
// config := config.Config {}
AppConfig = config.LoadConfig()
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
34 changes: 34 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// runCmd represents the run command
var runCmd = &cobra.Command{
Use: "run",
Short: "Run specific command",
Long: `Command that allows running specific global command.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("run called")
},
}

func init() {
rootCmd.AddCommand(runCmd)

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

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

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// runCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
25 changes: 24 additions & 1 deletion config.go → config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package main
package config

import (
"optimus/utils"

"github.com/spf13/viper"
)

type Config struct {
global Global
Expand Down Expand Up @@ -44,3 +50,20 @@ type ServiceTestCmd struct {
cmd Cmd
dependsOn []Service
}

func LoadConfig() Config {
dirPath := utils.ProjectRoot()
viper.SetConfigType("yaml")
viper.SetConfigName("optimus")
viper.AddConfigPath(dirPath)

viper.SetDefault("global", map[string]string{"shell_cmd": "bash -c"})

var c Config
err := viper.Unmarshal(&c)
if err != nil {
panic("Could not marchal config")
}

return Config{}
}
13 changes: 13 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"testing"
)

func TestConfigDefaults(t *testing.T) {

}

func TestConfigParsing(t *testing.T) {
// todo
}
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

src = ./.;

vendorHash = "sha256-3tO/+Mnvl/wpS7Ro3XDIVrlYTGVM680mcC15/7ON6qM=";
# vendorHash = pkgs.lib.fakeHash;
# vendorHash = "sha256-3tO/+Mnvl/wpS7Ro3XDIVrlYTGVM680mcC15/7ON6qM=";
vendorHash = pkgs.lib.fakeHash;

meta = with pkgs.lib; {
description = "Simple command-line snippet manager, written in Go";
Expand Down
4 changes: 4 additions & 0 deletions optimus.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
global:
shell_cmd: bash -c

include:
- ./frontend
- ./backend

init: |
echo "initialization commands"
Expand Down

0 comments on commit 4a72d20

Please sign in to comment.