Skip to content

Commit 08a1984

Browse files
committed
Restoring main
1 parent 1d5476f commit 08a1984

File tree

3 files changed

+64
-79
lines changed

3 files changed

+64
-79
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ release_todos.md
55

66

77
# package
8-
./lxc-compose
8+
/lxc-compose
99
templates

cmd/lxc-compose/main.go

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,72 @@
11
package main
22

33
import (
4-
"log"
4+
"fmt"
5+
"os"
56

6-
"github.com/larkinwc/proxmox-lxc-compose/internal/cli"
7+
"github.com/larkinwc/proxmox-lxc-compose/pkg/logging"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var (
14+
cfgFile string
15+
debugMode bool
16+
development bool
717
)
818

19+
func init() {
20+
cobra.OnInitialize(initConfig)
21+
22+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.lxc-compose.yaml)")
23+
rootCmd.PersistentFlags().BoolVar(&debugMode, "debug", false, "enable debug logging")
24+
rootCmd.PersistentFlags().BoolVar(&development, "dev", false, "enable development mode")
25+
}
26+
27+
func initConfig() {
28+
// Initialize logging first
29+
logLevel := "info"
30+
if debugMode {
31+
logLevel = "debug"
32+
}
33+
34+
if err := logging.Init(logging.Config{
35+
Level: logLevel,
36+
Development: development,
37+
}); err != nil {
38+
fmt.Printf("Error initializing logger: %v\n", err)
39+
os.Exit(1)
40+
}
41+
42+
// Load configuration file if specified
43+
if cfgFile != "" {
44+
viper.SetConfigFile(cfgFile)
45+
} else {
46+
home, err := os.UserHomeDir()
47+
cobra.CheckErr(err)
48+
49+
viper.AddConfigPath(home)
50+
viper.SetConfigType("yaml")
51+
viper.SetConfigName(".lxc-compose")
52+
}
53+
54+
if err := viper.ReadInConfig(); err == nil {
55+
logging.Info("Using config file", "path", viper.ConfigFileUsed())
56+
}
57+
}
58+
59+
var rootCmd = &cobra.Command{
60+
Use: "lxc-compose",
61+
Short: "Manage LXC containers using docker-compose like syntax",
62+
Long: `lxc-compose is a CLI tool that allows you to manage LXC containers
63+
using a docker-compose like syntax. It supports creating, starting, stopping,
64+
and managing containers defined in a YAML configuration file.`,
65+
}
66+
967
func main() {
10-
if err := cli.Execute(); err != nil {
11-
log.Fatal(err)
68+
if err := rootCmd.Execute(); err != nil {
69+
fmt.Println(err)
70+
os.Exit(1)
1271
}
1372
}

internal/cli/root.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)