75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/cloudmigration/drive-migrator/internal/tracker"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
statusCmd := &cobra.Command{
|
|
Use: "status [job-id]",
|
|
Short: "Show migration status",
|
|
Long: "Show status of migration jobs. If no job-id provided, shows all recent jobs.",
|
|
RunE: runStatus,
|
|
}
|
|
|
|
listCmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all migration jobs",
|
|
RunE: runList,
|
|
}
|
|
|
|
rootCmd.AddCommand(statusCmd)
|
|
rootCmd.AddCommand(listCmd)
|
|
}
|
|
|
|
func runStatus(cmd *cobra.Command, args []string) error {
|
|
trackFile := "migration.db" // Default, could be made configurable
|
|
|
|
t, err := tracker.NewTracker(trackFile)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to initialize tracker: %w", err)
|
|
}
|
|
defer t.Close()
|
|
|
|
if len(args) > 0 {
|
|
jobID := args[0]
|
|
job, err := t.GetJob(jobID)
|
|
if err != nil {
|
|
return fmt.Errorf("job not found: %w", err)
|
|
}
|
|
|
|
fmt.Printf("Job ID: %s\n", job.ID)
|
|
fmt.Printf("Source: %s\n", job.SourceName)
|
|
fmt.Printf("Destination: %s\n", job.DestName)
|
|
fmt.Printf("Status: %s\n", job.Status)
|
|
fmt.Printf("Start Time: %s\n", job.StartTime.Format("2006-01-02 15:04:05"))
|
|
if !job.EndTime.IsZero() {
|
|
fmt.Printf("End Time: %s\n", job.EndTime.Format("2006-01-02 15:04:05"))
|
|
fmt.Printf("Duration: %s\n", job.EndTime.Sub(job.StartTime))
|
|
}
|
|
if job.ErrorMessage != "" {
|
|
fmt.Printf("Error: %s\n", job.ErrorMessage)
|
|
}
|
|
|
|
completed := t.GetCompletedFiles(jobID)
|
|
fmt.Printf("Completed Files: %d\n", completed)
|
|
if job.TotalFiles > 0 {
|
|
percentage := float64(completed) / float64(job.TotalFiles) * 100
|
|
fmt.Printf("Progress: %.2f%%\n", percentage)
|
|
}
|
|
} else {
|
|
fmt.Println("Please provide a job ID. Use 'list' command to see all jobs.")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func runList(cmd *cobra.Command, args []string) error {
|
|
fmt.Println("Job listing feature will be implemented soon.")
|
|
fmt.Println("For now, check the migration.db file or use status with specific job ID.")
|
|
return nil
|
|
}
|