72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
|
|
// 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 <https://www.gnu.org/licenses/>.
|
||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"log"
|
||
|
|
"log/slog"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"headshed/infctl-cli/app"
|
||
|
|
"headshed/infctl-cli/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
|
||
|
|
var levelVar slog.LevelVar
|
||
|
|
levelVar.Set(slog.LevelDebug)
|
||
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: &levelVar}))
|
||
|
|
|
||
|
|
slog.SetDefault(logger)
|
||
|
|
|
||
|
|
if err := run(); err != nil {
|
||
|
|
log.Fatalf("Application error: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func run() error {
|
||
|
|
|
||
|
|
wd, err := os.Getwd()
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("failed to get current directory: %w", err)
|
||
|
|
}
|
||
|
|
baseConfigPath := wd + string(os.PathSeparator) + "base.json"
|
||
|
|
configPath := wd + string(os.PathSeparator) + "config.json"
|
||
|
|
|
||
|
|
baseConfig, err := config.ReadBaseConfig(baseConfigPath)
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("error reading base config file: %w", err)
|
||
|
|
}
|
||
|
|
customerConfig, err := config.ReadCustomerConfig(configPath)
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("error reading customer config file: %w", err)
|
||
|
|
}
|
||
|
|
appState, err := app.NewAppState(customerConfig, baseConfig, "app.db")
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("failed to initialize app state: %w", err)
|
||
|
|
}
|
||
|
|
defer func() {
|
||
|
|
if err := appState.DB.Close(); err != nil {
|
||
|
|
log.Printf("Error closing database: %v", err)
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
|
||
|
|
if err := appState.CreatePipeline(); err != nil {
|
||
|
|
return fmt.Errorf("failed to create customer project: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|