github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/pkg/misc/closure/genclosuredeps/genclosuredeps.go (about)

     1  /*
     2  Copyright 2013 The Camlistore Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8       http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // The genclosuredeps command, similarly to the closure depswriter.py tool,
    18  // outputs to os.Stdout for each .js file, which namespaces
    19  // it provides, and the namespaces it requires, hence helping
    20  // the closure library to resolve dependencies between those files.
    21  package main
    22  
    23  import (
    24  	"bytes"
    25  	"flag"
    26  	"fmt"
    27  	"io"
    28  	"log"
    29  	"net/http"
    30  	"os"
    31  
    32  	"camlistore.org/pkg/misc/closure"
    33  )
    34  
    35  func usage() {
    36  	fmt.Fprintf(os.Stderr, "Usage: genclosuredeps <dir>\n")
    37  	os.Exit(1)
    38  }
    39  
    40  func main() {
    41  	flag.Parse()
    42  	args := flag.Args()
    43  	if len(args) != 1 {
    44  		usage()
    45  	}
    46  	b, err := closure.GenDeps(http.Dir(args[0]))
    47  	if err != nil {
    48  		log.Fatal(err)
    49  	}
    50  	io.Copy(os.Stdout, bytes.NewReader(b))
    51  }