Skip to content

feat: providerArgs option to the push & pull command #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type PullOptions = {
normalize?: string
format: string
dryRun: boolean
providerArgs?: string
}

export const command = 'pull'
Expand Down Expand Up @@ -73,10 +74,15 @@ export const builder = (args: Argv): Argv<PullOptions> => {
default: false,
describe: 'run the pull command, but do not pull to locale messages of localization service'
})
.option('providerArgs', {
type: 'string',
alias: 'pa',
describe: `option to give parameters to the provider by using strings like URL query parameters (e.g. arg1=1&arg2=2).`
})
}

export const handler = async (args: Arguments<PullOptions>): Promise<unknown> => {
const { dryRun, normalize, format } = args
const { dryRun, normalize, format, providerArgs } = args
const ProviderFactory = loadProvider(args.provider)

if (ProviderFactory === null) {
Expand All @@ -97,7 +103,7 @@ export const handler = async (args: Arguments<PullOptions>): Promise<unknown> =>
try {
const locales = args.locales?.split(',').filter(p => p) as Locale[] || []
const provider = ProviderFactory(conf)
const messages = await provider.pull({ locales, dryRun, normalize, format })
const messages = await provider.pull({ locales, dryRun, normalize, format, providerArgs })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think providerArgs should be parsed to object, and it should be passed to provider.
Because it's user-friendly for providers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!
Please wait a moment.

await applyPullLocaleMessages(args.output, messages, args.dryRun)
// TODO: should refactor console message
console.log('pull success')
Expand Down
10 changes: 8 additions & 2 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type PushOptions = {
conf?: string
normalize?: string
dryRun: boolean
providerArgs?: string
} & PushableOptions

export const command = 'push'
Expand Down Expand Up @@ -64,10 +65,15 @@ export const builder = (args: Argv): Argv<PushOptions> => {
default: false,
describe: `run the push command, but do not apply to locale messages of localization service`
})
.option('providerArgs', {
type: 'string',
alias: 'pa',
describe: `option to give parameters to the provider by using strings like URL query parameters (e.g. arg1=1&arg2=2).`
})
}

export const handler = async (args: Arguments<PushOptions>): Promise<unknown> => {
const { dryRun, normalize } = args
const { dryRun, normalize, providerArgs } = args
const ProviderFactory = loadProvider(args.provider)

if (ProviderFactory === null) {
Expand All @@ -88,7 +94,7 @@ export const handler = async (args: Arguments<PushOptions>): Promise<unknown> =>
try {
const messages = getLocaleMessages(args)
const provider = ProviderFactory(conf)
await provider.push({ messages, dryRun, normalize })
await provider.push({ messages, dryRun, normalize, providerArgs })
// TODO: should refactor console message
console.log('push success')
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export interface Provider {
type CommonArguments = {
dryRun: boolean // whether the CLI run as dryRun mode
normalize?: string // normalization ways for locale messages or resource
providerArgs?: string // parameters to give to the provider
}

/**
Expand Down