-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
99 lines (82 loc) · 3.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/codevideo/codevideo-cli/cli"
"github.com/codevideo/codevideo-cli/cli/staticserver"
"github.com/codevideo/codevideo-cli/constants"
"github.com/codevideo/codevideo-cli/server"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
)
// const for version string
const version = "0.0.2"
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "codevideo",
Short: "CodeVideo's CLI tool",
Long: `CodeVideo's CLI tool for processing video jobs.`,
Run: func(cmd *cobra.Command, args []string) {
// Check for version flag first
showVersion, _ := cmd.Flags().GetBool("version")
if showVersion {
fmt.Printf("CodeVideo CLI v%s\n\n✨Sufficiently advanced technology is indistinguishable from magic.✨", version)
return
}
// apply logging level before anything
verbose, _ := cmd.Flags().GetBool("verbose")
if verbose {
log.SetLevel(log.DebugLevel)
log.Printf("CodeVideo CLI v%s - verbose logging enabled", version)
} else {
log.SetLevel(log.ErrorLevel)
}
// for either CLI or server mode, we need to start the required servers:
// start static server for the built gatsby files (7001) and the manifest files it needs (7000)
ctx := context.Background()
srv, err := staticserver.Start(ctx)
if err != nil {
log.Fatalf("Error starting static server: %v", err)
}
defer srv.Stop()
log.Printf("Manifest server started on port %d", constants.DEFAULT_MANIFEST_SERVER_PORT)
log.Printf("Static server started on port %d", constants.DEFAULT_GATSBY_PORT)
mode, _ := cmd.Flags().GetString("mode")
if mode == "serve" {
// Server functionality (API use case)
server.WatchForManifestFiles()
} else {
// CLI functionality
if err := cli.Execute(cmd); err != nil {
log.Fatalf("CLI execution failed: %v", err)
}
}
},
}
func init() {
// --mode or -m flag for running in server mode
rootCmd.Flags().StringP("mode", "m", "", "Run mode (use 'serve' for file watcher mode)")
// --project or -p flag for specifying project JSON data
rootCmd.Flags().StringP("project", "p", "", "Project data (Actions, Lesson, or Course) in JSON format")
// --output or -o flag for specifying output file path
rootCmd.Flags().StringP("output", "o", "", "Output file path")
// --orientation or -n flag for specifying video orientation
rootCmd.Flags().StringP("orientation", "n", "landscape", "Video orientation (landscape or portrait)")
// --resolution or -r flag for specifying video resolution
rootCmd.Flags().StringP("resolution", "r", "1080p", "Video resolution (1080p or 4K)")
// --verbose or -v flag for verbose output
rootCmd.Flags().BoolP("verbose", "v", false, "Verbose output")
// --version or -V flag for displaying version
rootCmd.Flags().BoolP("version", "V", false, "Display version information")
}
func main() {
// Load environment variables from .env file.
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
// Execute the root command
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}