Ejemplo n.º 1
0
        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// processes commands to extract tokens and secrets
        /// </summary>
        /// <param name="cmds"></param>
        /// <returns></returns>
        static void ProcessCmds( CmdLineParams cmds )
        {
            // ******
            var fileList = new List<string> { };
            var solutionFldr = string.Empty;
            var projectFldr = string.Empty;

            // ******
            for( int i = 0; i < cmds.Count; i += 1 ) {
                string cmd;
                string value;
                bool isCmd = cmds.GetCommand( i, out cmd, out value );

                // ******
                if( !isCmd ) {
                    //
                    // the file to process
                    //
                    var fn = FixFilePath( value );
                    if( !string.IsNullOrWhiteSpace( fn ) ) {
                        fileList.Add( fn );
                    }
                }
                else {
                    switch( cmd.ToLower() ) {
                        case "p":
                        case "project":
                            break;

                        case "s":
                        case "solution":
                            break;

                        case "w":
                        case "watch":
                            new Watcher( value, WatcherFileExts ).Run();
                            Environment.Exit( 0 );
                            break;

                        default:
                            Die( $"error: unknown command \"/{cmd}:{value}\"" );
                            break;
                    }
                }
            }

            // ******
            if( 0 == fileList.Count ) {
                Die( "error: no file name provided" );
            }
            else if( fileList.Count > 1 ) {
                Die( "error: more than one file name provided" );
            }
            else {
                var filePath = fileList.First();
                if( !File.Exists( filePath ) ) {
                    Die( $"error: could not locate file \"{filePath}\"" );
                }

                //	// ******
                //	var dataFilePath = GetDataFilePath( "Typescript\\raytracer.ts" );
                //	var runner = new Runner( dataFilePath ) { };
                //	Assert.NotNull( runner );
                //
                //	string result;
                //	string outExt;
                //	runner.Generate( out result, out outExt );
                //	Assert.True( TestNormalizeString( result ).StartsWith( "varVector=(function(){" ) );

                try {
                    var runner = new Runner( filePath ) { };

                    string result;
                    string outExt;
                    runner.Generate( true, out result, out outExt );
                }
                catch( Exception ex ) {
                    throw;
                }
            }

            // ******
            return;
        }
Ejemplo n.º 2
0
        /////////////////////////////////////////////////////////////////////////////
        //
        //
        //
        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// processes commands to extract tokens and secrets
        /// </summary>
        /// <param name="cmds"></param>
        /// <returns></returns>
        static void PreProcessCmds( CmdLineParams cmds )
        {
            // ******
            for( int i = 0; i < cmds.Count; /* incrementing counter handled below */ ) {
                string cmd;
                string value;
                bool isCmd = cmds.GetCommand( i, out cmd, out value );

                // ******
                bool cmdHandled = true;
                switch( cmd.ToLower() ) {
                    case "watchexts":
                        SetWatcherFileExts( value );
                        break;

                    default:
                        cmdHandled = false;
                        break;
                }

                // ******
                if( cmdHandled ) {
                    //
                    // remove the command we processed
                    //
                    cmds.Remove( i );
                }
                else {
                    //
                    // next command
                    //
                    i++;
                }
            }

            // ******
            return;
        }
Ejemplo n.º 3
0
		/////////////////////////////////////////////////////////////////////////////

		public bool InsertRange( int index, CmdLineParams p )
		{
			// ******
			if( null == p || index < 0 ) {
				return false;
			}
			else if( index >= Count ) {
				return AddRange( p );
			}

			// ******
			cmds.InsertRange( index, p.cmds );
			values.InsertRange( index, p.values );
			Count += p.Count;

			// ******
			return true;
		}
Ejemplo n.º 4
0
        static int Main( string [] args )
        {
            // ******
            //
            // load config file(s) if they can be found
            //
            // note: duplicates of the same command will be processed in the order in which they are
            // found, this allows a scenario where the "last config processed wins"; however since they
            // are each processed (new commands do not replace earliers commands with the same name) there
            // might be side effects from that processing - as of this time that is not at issue
            //
            var configFileName = AppName + ".config";
            var appDataFolder = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), AppName );
            var personalFolder = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.Personal ), AppName );

            var cmds = new CmdLineParams( args, false, false );

            //
            // try in app folder
            //
            cmds.LoadResponseFile( Path.Combine( LibInfo.CodeBase, configFileName ), false );

            //
            // then appication data folder (roaming)
            //
            cmds.LoadResponseFile( Path.Combine( appDataFolder, configFileName ), false );

            //
            // personal folder (documents)
            //
            cmds.LoadResponseFile( Path.Combine( personalFolder, configFileName ), false );

            // ******
            try {
                PreProcessCmds( cmds );
                ProcessCmds( cmds );

                ////Console.ReadKey();
                //if( Debugger.IsAttached ) {
                //	Debugger.Break();
                //}

                return 0;
            }
            catch( Exception ex ) {
                Console.WriteLine( ex.ToString() );

                //Console.ReadKey();
                if( Debugger.IsAttached ) {
                    Debugger.Break();
                }

                return 1;
            }
        }
Ejemplo n.º 5
0
		/////////////////////////////////////////////////////////////////////////////

		public bool AddRange( CmdLineParams p )
		{
			// ******
			if( null == p ) {
				return false;
			}

			// ******
			cmds.AddRange( p.cmds );
			values.AddRange( p.values );
			Count += p.Count;

			// ******
			return true;
		}