working on tui
This commit is contained in:
+55
-20
@@ -27,23 +27,51 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
}
|
||||
cfg.AbsRoot = abs
|
||||
|
||||
absOutput, err := filepath.Abs(cfg.OutputPath)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("resolve output path: %w", err)
|
||||
return result
|
||||
}
|
||||
absOutput = filepath.Join(filepath.Dir(absOutput), filepath.Base(absOutput)+"_dirmd")
|
||||
var outputBase string
|
||||
|
||||
if !cfg.AppendMode {
|
||||
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
|
||||
result.Error = fmt.Errorf("output %s exists (enable force)", absOutput)
|
||||
if cfg.AppendMode || cfg.SingleFile {
|
||||
absOutput, err := filepath.Abs(cfg.OutputPath)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("resolve output path: %w", err)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(absOutput, 0755); err != nil {
|
||||
result.Error = fmt.Errorf("create output dir: %w", err)
|
||||
return result
|
||||
if !cfg.AppendMode {
|
||||
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
|
||||
result.Error = fmt.Errorf("output %s exists (enable force or append)", absOutput)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
dir := filepath.Dir(absOutput)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
result.Error = fmt.Errorf("create output dir: %w", err)
|
||||
return result
|
||||
}
|
||||
|
||||
outputBase = absOutput
|
||||
} else {
|
||||
absOutput, err := filepath.Abs(cfg.OutputPath)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("resolve output path: %w", err)
|
||||
return result
|
||||
}
|
||||
absOutput = filepath.Join(filepath.Dir(absOutput), filepath.Base(absOutput)+"_dirmd")
|
||||
|
||||
if !cfg.AppendMode {
|
||||
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
|
||||
result.Error = fmt.Errorf("output %s exists (enable force)", absOutput)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(absOutput, 0755); err != nil {
|
||||
result.Error = fmt.Errorf("create output dir: %w", err)
|
||||
return result
|
||||
}
|
||||
|
||||
cfg.OutputPath = absOutput
|
||||
outputBase = absOutput
|
||||
}
|
||||
|
||||
walkResult, err := walker.Run(cfg)
|
||||
@@ -60,15 +88,14 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
repoName := filepath.Base(cfg.AbsRoot)
|
||||
|
||||
if cfg.VerticalSlices {
|
||||
generated, err := renderer.WriteSlices(walkResult, absOutput, repoName)
|
||||
generated, err := renderer.WriteSlices(walkResult, cfg.OutputPath, repoName)
|
||||
if err != nil {
|
||||
result.Error = err
|
||||
return result
|
||||
}
|
||||
result.Files = generated
|
||||
} else {
|
||||
indexBasename := "index_" + repoName + ".md"
|
||||
indexPath := filepath.Join(absOutput, indexBasename)
|
||||
indexPath := cfg.OutputPath
|
||||
if err := renderer.Write(walkResult, indexPath, cfg.AppendMode, cfg.SingleFile); err != nil {
|
||||
result.Error = err
|
||||
return result
|
||||
@@ -79,7 +106,7 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
if cfg.ProtonDrive {
|
||||
remoteDir := cfg.DrivePath
|
||||
if remoteDir == "" {
|
||||
remoteDir = "/my-files/md/" + filepath.Base(absOutput)
|
||||
remoteDir = "/my-files/md/" + filepath.Base(outputBase)
|
||||
}
|
||||
|
||||
if err := drive.CheckAuth(); err != nil {
|
||||
@@ -87,9 +114,17 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
return result
|
||||
}
|
||||
|
||||
if err := drive.UploadDir(absOutput, remoteDir); err != nil {
|
||||
result.Error = fmt.Errorf("drive upload: %w", err)
|
||||
return result
|
||||
if cfg.VerticalSlices {
|
||||
if err := drive.UploadDir(cfg.OutputPath, remoteDir); err != nil {
|
||||
result.Error = fmt.Errorf("drive upload: %w", err)
|
||||
return result
|
||||
}
|
||||
} else {
|
||||
indexPath := cfg.OutputPath
|
||||
if err := drive.Upload(indexPath, remoteDir); err != nil {
|
||||
result.Error = fmt.Errorf("drive upload: %w", err)
|
||||
return result
|
||||
}
|
||||
}
|
||||
result.Uploaded = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user