001    /*
002     * Copyright 2010-2013 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.jet.cli.js;
018    
019    import com.sampullara.cli.Argument;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.cli.common.CompilerArguments;
022    import org.jetbrains.k2js.facade.MainCallParameters;
023    
024    
025    /**
026     * NOTE: for now K2JSCompiler supports only minimal amount of parameters required to launch it from the plugin.
027     * You can specify path to the file where generated file will be stored, path to zipped library sources.
028     */
029    public class K2JSCompilerArguments extends CompilerArguments {
030        @Argument(value = "output", description = "Output file path")
031        public String outputFile;
032    
033        //NOTE: may well be a subject to change soon
034        @Argument(value = "libraryFiles", description = "Path to zipped lib sources or kotlin files")
035        public String[] libraryFiles;
036    
037        @Argument(value = "sourceFiles", description = "Source files (dir or file)")
038        public String[] sourceFiles;
039    
040        @Argument(value = "target", description = "Generate js files for specific ECMA version (3 or 5, default ECMA 3)")
041        public String target;
042    
043        @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
044        public boolean tags;
045    
046        @Argument(value = "verbose", description = "Enable verbose logging output")
047        public boolean verbose;
048    
049        @Argument(value = "version", description = "Display compiler version")
050        public boolean version;
051    
052        @Nullable
053        @Argument(value = "main", description = "Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)")
054        public String main;
055    
056        @Argument(value = "help", alias = "h", description = "Show help")
057        public boolean help;
058    
059        @Override
060        public boolean isHelp() {
061            return help;
062        }
063    
064        @Override
065        public boolean isTags() {
066            return tags;
067        }
068    
069        @Override
070        public boolean isVersion() {
071            return version;
072        }
073    
074        @Override
075        public boolean isVerbose() {
076            return verbose;
077        }
078    
079        @Override
080        public String getSrc() {
081            throw new IllegalStateException();
082        }
083    
084        public MainCallParameters createMainCallParameters() {
085            if ("noCall".equals(main)) {
086                return MainCallParameters.noCall();
087            }
088            else {
089                // TODO should we pass the arguments to the compiler?
090                return MainCallParameters.mainWithoutArguments();
091            }
092        }
093    }