<commit_before>/*
 * Copyright 2011, Red Hat, Inc. and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.zanata.client.commands.push;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.kohsuke.args4j.Option;
import org.zanata.client.commands.BooleanValueHandler;
import org.zanata.client.commands.ConfigurableProjectOptionsImpl;
import org.zanata.client.commands.PushPullCommand;
import org.zanata.client.commands.PushPullType;
import org.zanata.client.commands.ZanataCommand;
import org.zanata.client.config.LocaleList;
import org.zanata.util.StringUtil;

/**
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 *
 */
public class PushOptionsImpl extends ConfigurableProjectOptionsImpl implements PushOptions
{

   private static final boolean DEF_EXCLUDES = true;
   private static final boolean DEF_CASE_SENSITIVE = true;
   private static final boolean DEF_EXCLUDE_LOCALES = true;
   private static final boolean DEF_COPYTRANS = true;
   private static final int DEF_CHUNK_SIZE = 1024 * 1024;
   /** @see org.zanata.common.MergeType for options */
   private static final String DEF_MERGE_TYPE = "AUTO";
   private static final String DEF_PUSH_TYPE = "trans";

   private List<String> includes = new ArrayList<String>();
   private List<String> excludes = new ArrayList<String>();
   private List<String> fileTypes;
   private boolean defaultExcludes = DEF_EXCLUDES;
   private String mergeType = DEF_MERGE_TYPE;
   private boolean caseSensitive = DEF_CASE_SENSITIVE;
   private int chunkSize = DEF_CHUNK_SIZE;
   private boolean excludeLocaleFilenames = DEF_EXCLUDE_LOCALES;
   private boolean copyTrans = DEF_COPYTRANS;
   private String pushType = DEF_PUSH_TYPE;
   private File transDir;
   private File srcDir;
   private String sourceLang = "en-US";

   private String validate;
   private boolean dryRun;
   private String[] locales;
   private LocaleList effectiveLocales;

   @Override
   public ZanataCommand initCommand()
   {
      return new PushCommand(this);
   }

   @Override
   public String getCommandName()
   {
      return "push";
   }

   @Override
   public String getCommandDescription()
   {
      return "Pushes source text to a Zanata project version so that it can be translated.";
   }

   @Override
   public String getSourceLang()
   {
      return sourceLang;
   }

   @Option(name = "--src-lang", usage = "Language of source documents (defaults to en-US)")
   public void setSourceLang(String sourceLang)
   {
      this.sourceLang = sourceLang;
   }

   @Option(aliases = { "-l" }, name = "--locales", metaVar = "LOCALE1,LOCALE2,...", usage = "Locales to push to the server.\n" +
       "By default all locales in zanata.xml will be pushed.")
   public void setLocales(String locales)
   {
      this.locales = locales.split(",");
   }

   /**
    * Override the parent method as the push
    * command can have locales specified via command line.
    *
    * @return The locale map list taking into account the global locales in zanata.xml as well as the command line
    * argument ones.
    */
   @Override
   public LocaleList getLocaleMapList()
   {
      if(effectiveLocales == null)
      {
         effectiveLocales = PushPullCommand.getLocaleMapList(super.getLocaleMapList(), locales);
      }
      return effectiveLocales;
   }

   @Override
   public File getSrcDir()
   {
      return srcDir;
   }

   @Option(aliases = { "-s" }, name = "--src-dir", metaVar = "DIR", required = true, usage = "Base directory for source files (eg \".\", \"pot\", \"src/main/resources\")")
   public void setSrcDir(File file)
   {
      this.srcDir = file;
   }

   @Override
   public File getTransDir()
   {
      return transDir;
   }

   @Option(aliases = { "-t" }, name = "--trans-dir", metaVar = "DIR", required = true, usage = "Base directory for translated files (eg \".\", \"po\", \"src/main/resources\")")
   public void setTransDir(File transDir)
   {
      this.transDir = transDir;
   }

   @Override
   public boolean getCopyTrans()
   {
      return copyTrans;
   }

   public boolean isCopyTrans()
   {
      return copyTrans;
   }

   @Option(name = "--copy-trans", handler = BooleanValueHandler.class,
         usage = "Copy latest translations from equivalent messages/documents in the database (default: "+DEF_COPYTRANS+")")
   public void setCopyTrans(boolean copyTrans)
   {
      this.copyTrans = copyTrans;
   }

   @Override
   public String getMergeType()
   {
      return mergeType;
   }

   @Option(name = "--merge-type", metaVar = "TYPE", usage = "Merge type: \"auto\" (default) or \"import\" (DANGER!).")
   public void setMergeType(String mergeType)
   {
      this.mergeType = mergeType;
   }

   @Override
   public PushPullType getPushType()
   {
      return PushPullType.fromString(pushType);
   }

   @Option(name = "--push-type", metaVar = "TYPE", required = false, 
         usage = "Type of push to perform on the server:\n" +
                 "  \"source\" pushes source documents only.\n" +
                 "  \"trans\" (default) pushes translation documents only.\n" +
                 "  \"both\" pushes both source and translation documents.")
   public void setPushType(String pushType)
   {
      this.pushType = pushType;
   }

   @Override
   public List<String> getIncludes()
   {
      return includes;
   }

   @Option(name = "--includes", metaVar = "INCLUDES", usage = "Wildcard pattern to include files and directories. This parameter is only\n" +
           "needed for some project types, eg XLIFF, Properties. Usage\n" +
           "--includes=\"src/myfile*.xml,**/*.xlf\"")
   public void setIncludes(String includes)
   {<commit_msg>change default push type to source for cli client<commit_after>/*
 * Copyright 2011, Red Hat, Inc. and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.zanata.client.commands.push;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.kohsuke.args4j.Option;
import org.zanata.client.commands.BooleanValueHandler;
import org.zanata.client.commands.ConfigurableProjectOptionsImpl;
import org.zanata.client.commands.PushPullCommand;
import org.zanata.client.commands.PushPullType;
import org.zanata.client.commands.ZanataCommand;
import org.zanata.client.config.LocaleList;
import org.zanata.util.StringUtil;

/**
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 *
 */
public class PushOptionsImpl extends ConfigurableProjectOptionsImpl implements PushOptions
{

   private static final boolean DEF_EXCLUDES = true;
   private static final boolean DEF_CASE_SENSITIVE = true;
   private static final boolean DEF_EXCLUDE_LOCALES = true;
   private static final boolean DEF_COPYTRANS = true;
   private static final int DEF_CHUNK_SIZE = 1024 * 1024;
   /** @see org.zanata.common.MergeType for options */
   private static final String DEF_MERGE_TYPE = "AUTO";
   private static final String DEF_PUSH_TYPE = "source";

   private List<String> includes = new ArrayList<String>();
   private List<String> excludes = new ArrayList<String>();
   private List<String> fileTypes;
   private boolean defaultExcludes = DEF_EXCLUDES;
   private String mergeType = DEF_MERGE_TYPE;
   private boolean caseSensitive = DEF_CASE_SENSITIVE;
   private int chunkSize = DEF_CHUNK_SIZE;
   private boolean excludeLocaleFilenames = DEF_EXCLUDE_LOCALES;
   private boolean copyTrans = DEF_COPYTRANS;
   private String pushType = DEF_PUSH_TYPE;
   private File transDir;
   private File srcDir;
   private String sourceLang = "en-US";

   private String validate;
   private boolean dryRun;
   private String[] locales;
   private LocaleList effectiveLocales;

   @Override
   public ZanataCommand initCommand()
   {
      return new PushCommand(this);
   }

   @Override
   public String getCommandName()
   {
      return "push";
   }

   @Override
   public String getCommandDescription()
   {
      return "Pushes source text to a Zanata project version so that it can be translated.";
   }

   @Override
   public String getSourceLang()
   {
      return sourceLang;
   }

   @Option(name = "--src-lang", usage = "Language of source documents (defaults to en-US)")
   public void setSourceLang(String sourceLang)
   {
      this.sourceLang = sourceLang;
   }

   @Option(aliases = { "-l" }, name = "--locales", metaVar = "LOCALE1,LOCALE2,...", usage = "Locales to push to the server.\n" +
       "By default all locales in zanata.xml will be pushed.")
   public void setLocales(String locales)
   {
      this.locales = locales.split(",");
   }

   /**
    * Override the parent method as the push
    * command can have locales specified via command line.
    *
    * @return The locale map list taking into account the global locales in zanata.xml as well as the command line
    * argument ones.
    */
   @Override
   public LocaleList getLocaleMapList()
   {
      if(effectiveLocales == null)
      {
         effectiveLocales = PushPullCommand.getLocaleMapList(super.getLocaleMapList(), locales);
      }
      return effectiveLocales;
   }

   @Override
   public File getSrcDir()
   {
      return srcDir;
   }

   @Option(aliases = { "-s" }, name = "--src-dir", metaVar = "DIR", required = true, usage = "Base directory for source files (eg \".\", \"pot\", \"src/main/resources\")")
   public void setSrcDir(File file)
   {
      this.srcDir = file;
   }

   @Override
   public File getTransDir()
   {
      return transDir;
   }

   @Option(aliases = { "-t" }, name = "--trans-dir", metaVar = "DIR", required = true, usage = "Base directory for translated files (eg \".\", \"po\", \"src/main/resources\")")
   public void setTransDir(File transDir)
   {
      this.transDir = transDir;
   }

   @Override
   public boolean getCopyTrans()
   {
      return copyTrans;
   }

   public boolean isCopyTrans()
   {
      return copyTrans;
   }

   @Option(name = "--copy-trans", handler = BooleanValueHandler.class,
         usage = "Copy latest translations from equivalent messages/documents in the database (default: "+DEF_COPYTRANS+")")
   public void setCopyTrans(boolean copyTrans)
   {
      this.copyTrans = copyTrans;
   }

   @Override
   public String getMergeType()
   {
      return mergeType;
   }

   @Option(name = "--merge-type", metaVar = "TYPE", usage = "Merge type: \"auto\" (default) or \"import\" (DANGER!).")
   public void setMergeType(String mergeType)
   {
      this.mergeType = mergeType;
   }

   @Override
   public PushPullType getPushType()
   {
      return PushPullType.fromString(pushType);
   }

   @Option(name = "--push-type", metaVar = "TYPE", required = false, 
         usage = "Type of push to perform on the server:\n" +
                 "  \"source\" (default) pushes source documents only.\n" +
                 "  \"trans\" pushes translation documents only.\n" +
                 "  \"both\" pushes both source and translation documents.")
   public void setPushType(String pushType)
   {
      this.pushType = pushType;
   }

   @Override
   public List<String> getIncludes()
   {
      return includes;
   }

   @Option(name = "--includes", metaVar = "INCLUDES", usage = "Wildcard pattern to include files and directories. This parameter is only\n" +
           "needed for some project types, eg XLIFF, Properties. Usage\n" +
           "--includes=\"src/myfile*.xml,**/*.xlf\"")
   public void setIncludes(String includes)
   {
{'fraction_non_alphanumeric': 0.10201160250131847, 'fraction_numerical': 0.004219091388533112, 'mean_word_length': 3.2206677265500794, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987465', 'n_tokens_mistral': 3946, 'n_tokens_neox': 3777, 'n_words': 1256}