use config value for pm path
This commit is contained in:
@@ -81,19 +81,19 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx); err != nil {
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx, app.Config.AppDir); err != nil {
|
||||
cmd.Printf("Failed to submit survey responses: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx); err != nil {
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx, app.Config.AppDir); err != nil {
|
||||
cmd.Printf("Failed to submit survey responses: %v\n", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(context.Background()); err != nil {
|
||||
if err := mongoStorage.SubmitSurveyResponsesCmd(context.Background(), app.Config.AppDir); err != nil {
|
||||
cmd.Printf("Failed to submit survey responses on shutdown: %v\n", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -23,13 +23,13 @@ func New(ctx context.Context, config Config, opts ...Option) (*App, func(), erro
|
||||
}
|
||||
|
||||
if !config.AutoInit {
|
||||
if err := b.initializer.Init(config.BeadsDBPath); err != nil {
|
||||
if err := b.initializer.Init(config.AppDir + "/db.db"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if b.issueService == nil {
|
||||
sqliteStore, err := beads.NewSQLiteStorage(b.ctx, config.BeadsDBPath)
|
||||
sqliteStore, err := beads.NewSQLiteStorage(b.ctx, config.AppDir+"/db.db")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func defaultBuilder(ctx context.Context, config Config) *AppBuilder {
|
||||
}
|
||||
|
||||
func defaultLogger(config Config, lifecycle *Lifecycle) *slog.Logger {
|
||||
statsDir := filepath.Dir(config.StatisticsStoragePath)
|
||||
statsDir := filepath.Dir(config.AppDir + "/stats.json")
|
||||
if statsDir == "" {
|
||||
statsDir = "."
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ var SubmitCmd = &cobra.Command{
|
||||
|
||||
defer db.Close()
|
||||
|
||||
if err := db.SubmitSurveyResponsesCmd(cmd.Context()); err != nil {
|
||||
if err := db.SubmitSurveyResponsesCmd(cmd.Context(), app.Config.AppDir); err != nil {
|
||||
return fmt.Errorf("failed to submit survey responses: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ type Config struct {
|
||||
DbUri string
|
||||
AutoInit bool
|
||||
RootCmd string
|
||||
AppDir string
|
||||
WebAddress string
|
||||
BeadsDBPath string
|
||||
IssuePrefix string
|
||||
StatisticsStoragePath string
|
||||
ActionLogger func(string)
|
||||
StatisticsStoragePath string
|
||||
}
|
||||
|
||||
var BaseConfig = Config{
|
||||
@@ -19,7 +19,7 @@ var BaseConfig = Config{
|
||||
RootCmd: "pm",
|
||||
IssuePrefix: "pm",
|
||||
WebAddress: ":8080",
|
||||
BeadsDBPath: "./.pm/db.db",
|
||||
AppDir: "./.pm",
|
||||
StatisticsStoragePath: "./.pm/stats.json",
|
||||
}
|
||||
|
||||
@@ -50,11 +50,6 @@ func (c Config) WithWebAddress(webAddress string) Config {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithBeadsDBPath(beadsDBPath string) Config {
|
||||
c.BeadsDBPath = beadsDBPath
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithIssuePrefix(issuePrefix string) Config {
|
||||
c.IssuePrefix = issuePrefix
|
||||
return c
|
||||
|
||||
@@ -83,8 +83,8 @@ func (s *MongoStorage) Close() error {
|
||||
return s.client.Disconnect(context.Background())
|
||||
}
|
||||
|
||||
func (s *MongoStorage) SubmitSurveyResponsesCmd(ctx context.Context) error {
|
||||
pmDir := "./.pm/"
|
||||
func (s *MongoStorage) SubmitSurveyResponsesCmd(ctx context.Context, dir string) error {
|
||||
pmDir := dir
|
||||
userStatscollection := s.client.Database("Responses").Collection("stats")
|
||||
taskMetricsCollection := s.client.Database("Responses").Collection("metrics")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user