ibragdzh
ibragdzh
TTask
Created by ibragdzh on 11/7/2024 in #help
Parentheses in commands
Unfortunately,
$ task migrate/create
task: [migrate/create] read -p "enter name: " NAME; TIMESTAMP=$$(date +%s); FILENAME="migrations/$${TIMESTAMP}_$${NAME}.go"; mkdir -p internal/persistence/migrations; echo $'package migrations\n\nimport (\n \\"github.com/rs/zerolog/log\\"\n migrate \\"github.com/xakep666/mongo-migrate\\"\n \\"go.mongodb.org/mongo-driver/mongo\\"\n)\n\n//nolint:gochecknoinits // used for migrations\nfunc init() {\n err := migrate.Register(\n func(db *mongo.Database) error {\n return nil\n },\n func(db *mongo.Database) error {\n return nil\n },\n )\n if err != nil {\n log.Err(err).Msg(\\"$${TIMESTAMP}_$${NAME} migration error\\")\n }\n}\n' > $$FILENAME; echo "Migrate file $$FILENAME created!"
task: Failed to run task "migrate/create": 1:43: a command can only contain words and redirects; encountered (
$ task migrate/create
task: [migrate/create] read -p "enter name: " NAME; TIMESTAMP=$$(date +%s); FILENAME="migrations/$${TIMESTAMP}_$${NAME}.go"; mkdir -p internal/persistence/migrations; echo $'package migrations\n\nimport (\n \\"github.com/rs/zerolog/log\\"\n migrate \\"github.com/xakep666/mongo-migrate\\"\n \\"go.mongodb.org/mongo-driver/mongo\\"\n)\n\n//nolint:gochecknoinits // used for migrations\nfunc init() {\n err := migrate.Register(\n func(db *mongo.Database) error {\n return nil\n },\n func(db *mongo.Database) error {\n return nil\n },\n )\n if err != nil {\n log.Err(err).Msg(\\"$${TIMESTAMP}_$${NAME} migration error\\")\n }\n}\n' > $$FILENAME; echo "Migrate file $$FILENAME created!"
task: Failed to run task "migrate/create": 1:43: a command can only contain words and redirects; encountered (
9 replies
TTask
Created by ibragdzh on 11/7/2024 in #help
Parentheses in commands
Thanks. Updated this multiline var, now returned to the another error saying no parentheses:
$ task migrate/create
task: [migrate/create] read -p "enter name: " NAME; TIMESTAMP=$$(date +%s); FILENAME="migrations/$${TIMESTAMP}_$${NAME}.go"; mkdir -p internal/persistence/migrations; echo "package migrations

import \(
\"github.com/rs/zerolog/log\"
migrate \"github.com/xakep666/mongo-migrate\"
\"go.mongodb.org/mongo-driver/mongo\"
\)

//nolint:gochecknoinits // used for migrations
func init\(\) {
err := migrate.Register\(
func\(db *mongo.Database\) error {
return nil
},
func\(db *mongo.Database\) error {
return nil
},
\)
if err != nil {
log.Err\(err\).Msg\(\"$${TIMESTAMP}_$${NAME} migration error\"\)
}
}
" > $$FILENAME; echo "Migrate file $$FILENAME created!"
task: Failed to run task "migrate/create": 1:43: a command can only contain words and redirects; encountered (
$ task migrate/create
task: [migrate/create] read -p "enter name: " NAME; TIMESTAMP=$$(date +%s); FILENAME="migrations/$${TIMESTAMP}_$${NAME}.go"; mkdir -p internal/persistence/migrations; echo "package migrations

import \(
\"github.com/rs/zerolog/log\"
migrate \"github.com/xakep666/mongo-migrate\"
\"go.mongodb.org/mongo-driver/mongo\"
\)

//nolint:gochecknoinits // used for migrations
func init\(\) {
err := migrate.Register\(
func\(db *mongo.Database\) error {
return nil
},
func\(db *mongo.Database\) error {
return nil
},
\)
if err != nil {
log.Err\(err\).Msg\(\"$${TIMESTAMP}_$${NAME} migration error\"\)
}
}
" > $$FILENAME; echo "Migrate file $$FILENAME created!"
task: Failed to run task "migrate/create": 1:43: a command can only contain words and redirects; encountered (
Trying both escaped and non-escaped parentheses didn't work for me
9 replies
TTask
Created by ibragdzh on 11/7/2024 in #help
Parentheses in commands
just mentioning, the answer is message below
9 replies
TTask
Created by ibragdzh on 11/7/2024 in #help
Parentheses in commands
Sure, here it is:
version: '3'

dotenv: ['.env']

vars:
MIGRATION_FILE: "
package migrations

import (
\"github.com/rs/zerolog/log\"
migrate \"github.com/xakep666/mongo-migrate\"
\"go.mongodb.org/mongo-driver/mongo\"
)

//nolint:gochecknoinits // used for migrations
func init() {
err := migrate.Register(
func(db *mongo.Database) error {
return nil
},
func(db *mongo.Database) error {
return nil
},
)
if err != nil {
log.Err(err).Msg(\"$${TIMESTAMP}_$${NAME} migration error\")
}
}
"

tasks:
migrate/create:
cmds:
- "read -p \"enter name: \" NAME; \
TIMESTAMP=$$(date +%s); \
FILENAME=\"migrations/$${TIMESTAMP}_$${NAME}.go\"; \
mkdir -p internal/persistence/migrations; \
echo \"{{.MIGRATION_FILE}}\" > $$FILENAME; \
echo \"Migrate file $$FILENAME created!\""
version: '3'

dotenv: ['.env']

vars:
MIGRATION_FILE: "
package migrations

import (
\"github.com/rs/zerolog/log\"
migrate \"github.com/xakep666/mongo-migrate\"
\"go.mongodb.org/mongo-driver/mongo\"
)

//nolint:gochecknoinits // used for migrations
func init() {
err := migrate.Register(
func(db *mongo.Database) error {
return nil
},
func(db *mongo.Database) error {
return nil
},
)
if err != nil {
log.Err(err).Msg(\"$${TIMESTAMP}_$${NAME} migration error\")
}
}
"

tasks:
migrate/create:
cmds:
- "read -p \"enter name: \" NAME; \
TIMESTAMP=$$(date +%s); \
FILENAME=\"migrations/$${TIMESTAMP}_$${NAME}.go\"; \
mkdir -p internal/persistence/migrations; \
echo \"{{.MIGRATION_FILE}}\" > $$FILENAME; \
echo \"Migrate file $$FILENAME created!\""
I'm migrating from Makefile and this command was working as expected with make, but I don't yet know how do I adapt it to Taskfile
9 replies