rename --git-repo to --output-dir again

This commit is contained in:
2025-07-06 00:17:37 +00:00
parent c84986a443
commit bf80fd057d
2 changed files with 11 additions and 11 deletions

View File

@ -124,13 +124,13 @@ func (rb *RouterBackup) RunCommand(command string) (string, error) {
}
// BackupCommands runs multiple commands and saves outputs to files
func (rb *RouterBackup) BackupCommands(commands []string, gitRepo string) error {
if err := os.MkdirAll(gitRepo, 0755); err != nil {
return fmt.Errorf("failed to create directory %s: %v", gitRepo, err)
func (rb *RouterBackup) BackupCommands(commands []string, outputDir string) error {
if err := os.MkdirAll(outputDir, 0755); err != nil {
return fmt.Errorf("failed to create directory %s: %v", outputDir, err)
}
filename := fmt.Sprintf("%s.txt", rb.hostname)
filepath := filepath.Join(gitRepo, filename)
filepath := filepath.Join(outputDir, filename)
// Truncate file at start
file, err := os.Create(filepath)
@ -220,7 +220,7 @@ func main() {
var password string
var keyFile string
var port int
var gitRepo string
var outputDir string
var rootCmd = &cobra.Command{
Use: "router_backup",
@ -286,7 +286,7 @@ func main() {
continue
}
err = backup.BackupCommands(commands, gitRepo)
err = backup.BackupCommands(commands, outputDir)
backup.Disconnect()
if err != nil {
@ -305,7 +305,7 @@ func main() {
rootCmd.Flags().StringVar(&password, "password", "", "SSH password")
rootCmd.Flags().StringVar(&keyFile, "key-file", "", "SSH private key file path")
rootCmd.Flags().IntVar(&port, "port", 22, "SSH port")
rootCmd.Flags().StringVar(&gitRepo, "git-repo", "/tmp", "Git repository directory for command output files")
rootCmd.Flags().StringVar(&outputDir, "output-dir", "/tmp", "Output directory for command output files")
rootCmd.MarkFlagRequired("config")