@@ -143,64 +143,6 @@ system key per account and uses it as a foothold to rewrite and
143143version-control access. A database becomes the source of truth.
144144
145145Running without a subcommand will launch the interactive TUI.` ,
146- // // PreRun for all subsequent commands
147- // PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
148- // // Load optional config file argument from cli
149- // var optional_config_path *string
150- // if path, err := cmd.PersistentFlags().GetString("config"); err == nil {
151- // // make sure the user provided file exists, to mitigate unwanted behaivio, like loading unwanted default configs
152- // if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
153- // return err
154- // }
155- // optional_config_path = &path
156- // }
157-
158- // // Load config
159- // type Config struct {
160- // Database struct {
161- // Type string `mapstructure:"type"`
162- // Dsn string `mapstructure:"dsn"`
163- // } `mapstructure:"database"`
164- // Language string `mapstructure:"language"`
165- // }
166-
167- // defauls := map[string]any{
168- // "database.type": "sqlite",
169- // "database.dsn": "./keymaster.db",
170- // "language": "en",
171- // }
172-
173- // config, err := config.LoadConfig[Config](cmd, defauls, optional_config_path)
174- // if err != nil {
175- // return fmt.Errorf("error loading config: %w", err)
176- // }
177-
178- // // Initialize i18n
179- // i18n.Init(config.Language)
180-
181- // // Initialize the database
182- // if err := db.InitDB(config.Database.Type, config.Database.Dsn); err != nil {
183- // return errors.New(i18n.T("config.error_init_db", err))
184- // }
185-
186- // // // Initialize the database for all commands.
187- // // // Viper has already read the config by this point.
188- // // dbType := viper.GetString("database.type")
189- // // dsn := viper.GetString("database.dsn")
190- // // if err := db.InitDB(dbType, dsn); err != nil {
191- // // return errors.New(i18n.T("config.error_init_db", err))
192- // // }
193-
194- // // Recover from any previous crashes
195- // if err := bootstrap.RecoverFromCrash(); err != nil {
196- // log.Printf("Bootstrap recovery error: %v", err)
197- // }
198-
199- // // Start background session reaper
200- // bootstrap.StartSessionReaper()
201-
202- // return nil
203- // },
204146 PreRunE : setupDefaultServices ,
205147 Run : func (cmd * cobra.Command , args []string ) {
206148 // The database is already initialized by PersistentPreRunE.
@@ -252,93 +194,6 @@ Running without a subcommand will launch the interactive TUI.`,
252194 return cmd
253195}
254196
255- // initConfig reads in a configuration file and environment variables.
256- // It uses Viper to search for a config file (e.g., .keymaster.yaml) in the home
257- // and current directories. If a config file is not found, it attempts to create
258- // a default one. It also binds environment variables prefixed with "KEYMASTER".
259- // func initConfig() error {
260- // if cfgFile != "" {
261- // // Use config file from the flag.
262- // viper.SetConfigFile(cfgFile)
263- // } else {
264- // // Search for config in standard locations.
265- // // 1. Look for the new 'config.yaml' in the user's config directory.
266- // configDir, err := os.UserConfigDir()
267- // if err == nil {
268- // keymasterConfigDir := filepath.Join(configDir, "keymaster")
269- // newConfigPath := filepath.Join(keymasterConfigDir, "config.yaml")
270- // if _, err := os.Stat(newConfigPath); err == nil {
271- // // If the new config file exists, use it exclusively.
272- // viper.SetConfigFile(newConfigPath)
273- // }
274- // }
275-
276- // // 2. If no new config was found, fall back to searching for the old
277- // // '.keymaster.yaml' in the current directory for backward compatibility.
278- // if viper.ConfigFileUsed() == "" {
279- // viper.AddConfigPath(".")
280- // viper.SetConfigName(".keymaster")
281- // viper.SetConfigType("yaml")
282- // }
283- // }
284-
285- // viper.SetEnvPrefix("KEYMASTER")
286- // viper.AutomaticEnv() // read in environment variables that match
287-
288- // // Attempt to read the config file.
289- // if err := viper.ReadInConfig(); err != nil {
290- // if _, ok := err.(viper.ConfigFileNotFoundError); ok {
291- // // Config file not found. If no specific file was requested, create a default one.
292- // if cfgFile == "" {
293- // return createDefaultConfig()
294- // }
295- // } else {
296- // // Config file was found but another error was produced
297- // return fmt.Errorf("error reading config file: %w", err)
298- // }
299- // }
300- // return nil
301- // }
302-
303- // createDefaultConfig creates a default configuration file in the user's
304- // standard config directory (e.g., ~/.config/keymaster/config.yaml).
305- // func createDefaultConfig() error {
306- // configDir, err := os.UserConfigDir()
307- // if err != nil {
308- // // Cannot find a standard config dir, so we don't create a file.
309- // // The app will run with in-memory defaults.
310- // return nil
311- // }
312-
313- // keymasterConfigDir := filepath.Join(configDir, "keymaster")
314- // if err := os.MkdirAll(keymasterConfigDir, 0755); err != nil {
315- // return fmt.Errorf("failed to create config directory: %w", err)
316- // }
317-
318- // defaultConfigPath := filepath.Join(keymasterConfigDir, "config.yaml")
319-
320- // // Only write the file if it doesn't already exist.
321- // if _, err := os.Stat(defaultConfigPath); os.IsNotExist(err) {
322- // // The default DSN should be an absolute path to a database file in the same config directory.
323- // defaultDBPath := filepath.Join(keymasterConfigDir, "keymaster.db")
324- // // On Windows, we need to escape backslashes for the YAML string.
325- // escapedDBPath := strings.ReplaceAll(defaultDBPath, `\`, `\\`)
326-
327- // defaultContent := `# Keymaster configuration file.
328- // # This file is automatically generated with default values.
329- // # You can modify these settings to configure Keymaster.
330-
331- // database:
332- // type: sqlite
333- // dsn: ` + escapedDBPath + `
334-
335- // language: en
336- // `
337- // return os.WriteFile(defaultConfigPath, []byte(defaultContent), 0644)
338- // }
339- // return nil
340- // }
341-
342197// deployCmd represents the 'deploy' command.
343198// It handles rendering the authorized_keys file from the database and deploying it
344199// to one or all managed accounts.
0 commit comments