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 = "sourcemap", description = "Generate SourceMap")
041        public boolean sourcemap;
042    
043        @Argument(value = "target", description = "Generate js files for specific ECMA version (3 or 5, default ECMA 3)")
044        public String target;
045    
046        @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
047        public boolean tags;
048    
049        @Argument(value = "verbose", description = "Enable verbose logging output")
050        public boolean verbose;
051    
052        @Argument(value = "version", description = "Display compiler version")
053        public boolean version;
054    
055        @Nullable
056        @Argument(value = "main", description = "Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)")
057        public String main;
058    
059        @Argument(value = "help", alias = "h", description = "Show help")
060        public boolean help;
061    
062        @Override
063        public boolean isHelp() {
064            return help;
065        }
066    
067        @Override
068        public boolean isTags() {
069            return tags;
070        }
071    
072        @Override
073        public boolean isVersion() {
074            return version;
075        }
076    
077        @Override
078        public boolean isVerbose() {
079            return verbose;
080        }
081    
082        @Override
083        public String getSrc() {
084            throw new IllegalStateException();
085        }
086    
087        public MainCallParameters createMainCallParameters() {
088            if ("noCall".equals(main)) {
089                return MainCallParameters.noCall();
090            }
091            else {
092                // TODO should we pass the arguments to the compiler?
093                return MainCallParameters.mainWithoutArguments();
094            }
095        }
096    }