Skip to content
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

Add new 'crowdin list branches' command #300

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.crowdin.cli.commands.actions;

import com.crowdin.cli.client.Client;
import com.crowdin.cli.client.Project;
import com.crowdin.cli.commands.functionality.DryrunBranches;
import com.crowdin.cli.properties.PropertiesBean;
import com.crowdin.cli.utils.console.ConsoleSpinner;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
import static com.crowdin.cli.utils.console.ExecutionStatus.ERROR;
import static com.crowdin.cli.utils.console.ExecutionStatus.OK;

public class ListBranchesAction implements Action {

private boolean noProgress;
private boolean plainView;

public ListBranchesAction(boolean noProgress, boolean plainView) {
this.noProgress = noProgress || plainView;
this.plainView = plainView;
}

@Override
public void act(PropertiesBean pb, Client client) {
Project project;
try {
if (!plainView) {
ConsoleSpinner.start(RESOURCE_BUNDLE.getString("message.spinner.fetching_project_info"), this.noProgress);
}
project = client.downloadFullProject();
ConsoleSpinner.stop(OK);
} catch (Exception e) {
ConsoleSpinner.stop(ERROR);
throw new RuntimeException(RESOURCE_BUNDLE.getString("error.collect_project_info"), e);
}

new DryrunBranches(project.getBranches())
.run(false, plainView);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.crowdin.cli.commands.functionality;

import com.crowdin.client.sourcefiles.model.Branch;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DryrunBranches extends Dryrun {

private Map<Long, Branch> branches;

public DryrunBranches(Map<Long, Branch> branches) {
super("message.branch");
this.branches = branches;
}

@Override
protected List<String> getFiles() {
return branches.values().stream()
.map(Branch::getName)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.crowdin.cli.commands.picocli;

import com.crowdin.cli.client.Client;
import com.crowdin.cli.client.CrowdinClient;
import com.crowdin.cli.commands.actions.Action;
import com.crowdin.cli.commands.actions.ListBranchesAction;
import com.crowdin.cli.properties.PropertiesBean;
import picocli.CommandLine;

@CommandLine.Command(
name = "branches"
)
public class ListBranchesSubcommand extends Command {

@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
protected boolean plainView;

@CommandLine.Mixin
private PropertiesBuilderCommandPart propertiesBuilderCommandPart;

@Override
public void run() {
PropertiesBean pb = propertiesBuilderCommandPart.buildPropertiesBean();
Client client = new CrowdinClient(pb.getApiToken(), pb.getBaseUrl(), Long.parseLong(pb.getProjectId()));

Action action = new ListBranchesAction(this.noProgress, this.plainView);
action.act(pb, client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
subcommands = {
ListProjectSubcommand.class,
ListSourcesSubcommand.class,
ListTranslationsSubcommand.class
ListTranslationsSubcommand.class,
ListBranchesSubcommand.class
})
public class ListSubcommand extends HelpCommand {
@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ crowdin.list.usage.customSynopsis=@|fg(green) crowdin list|@ [SUBCOMMAND] [CONFI
crowdin.list.translations.usage.description=List information about the translation files that match the wild-card pattern contained in the current project
crowdin.list.translations.usage.customSynopsis=@|fg(green) crowdin list translations|@ [CONFIG OPTIONS] [OPTIONS]

#CROWDIN LIST BRANCHES COMMAND
crowdin.list.branches.usage.description=List branches in the current project
crowdin.list.branches.usage.customSynopsis=@|fg(green) crowdin list branches|@ [CONFIG OPTIONS] [OPTIONS]

# CROWDIN COMMAND
crowdin.usage.description.0=Crowdin CLI is a command-line tool that allows you to manage and synchronize localization resources with your Crowdin project.
crowdin.usage.description.1=This tool requires you to create a configuration file. For more details see https://support.crowdin.com/configuration-file/
Expand Down