Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 6f07a13

Browse files
committed
Initial commit
0 parents  commit 6f07a13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+8765
-0
lines changed

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
BSD License
2+
3+
For parse-cli software
4+
5+
Copyright (c) 2015, Facebook, Inc. All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* Neither the name Facebook nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific
19+
prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PATENTS

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Additional Grant of Patent Rights Version 2
2+
3+
"Software" means the parse-cli software distributed by Facebook, Inc.
4+
5+
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
6+
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
7+
(subject to the termination provision below) license under any Necessary
8+
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
9+
transfer the Software. For avoidance of doubt, no license is granted under
10+
Facebook’s rights in any patent claims that are infringed by (i) modifications
11+
to the Software made by you or any third party or (ii) the Software in
12+
combination with any software or other technology.
13+
14+
The license granted hereunder will terminate, automatically and without notice,
15+
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
16+
directly or indirectly, or take a direct financial interest in, any Patent
17+
Assertion: (i) against Facebook or any of its subsidiaries or corporate
18+
affiliates, (ii) against any party if such Patent Assertion arises in whole or
19+
in part from any software, technology, product or service of Facebook or any of
20+
its subsidiaries or corporate affiliates, or (iii) against any party relating
21+
to the Software. Notwithstanding the foregoing, if Facebook or any of its
22+
subsidiaries or corporate affiliates files a lawsuit alleging patent
23+
infringement against you in the first instance, and you respond by filing a
24+
patent infringement counterclaim in that lawsuit against that party that is
25+
unrelated to the Software, the license granted hereunder will not terminate
26+
under section (i) of this paragraph due to such counterclaim.
27+
28+
A "Necessary Claim" is a claim of a patent owned by Facebook that is
29+
necessarily infringed by the Software standing alone.
30+
31+
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
32+
or contributory infringement or inducement to infringe any patent, including a
33+
cross-claim or counterclaim.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Parse Command Line Tool
2+
=======
3+
4+
The `Parse Command Line Tool` allows you to interact with your Cloud Code from the terminal.
5+
6+
For more information please visit [Parse](https://parse.com/docs/js/guide#command-line).
7+
8+
Overview
9+
--------
10+
Parse Command Line Tool can be used to perform various actions on your Parse app.
11+
It can be used to create new Parse apps, deploy Cloud Code to an app, view all releases for an app, etc.
12+
13+
You can install `Parse Command Line Tool` by following instructions at [parse-cli](https://parse.com/apps/quickstart#cloud_code/).
14+
15+
Alternatively, you can just type the following command (assuming you already have Go installed).
16+
```bash
17+
go get github.com/ParsePlatform/parse-cli
18+
```
19+
This installs a binary called `parse-cli` at `$GOPATH/bin`.
20+
21+
The following commands are currently available in the `Parse Command Line Tool`:
22+
```bash
23+
add Adds a new Parse app to config in current Cloud Code directory
24+
default Sets or gets the default Parse app
25+
deploy Deploys a Parse app
26+
develop Monitors for changes to code and deploys, also tails parse logs
27+
functions List Cloud Code functions and function webhooks
28+
generate Generates a sample express app in the current project directory
29+
jssdk Sets the Parse JavaScript SDK version to use in Cloud Code
30+
list Lists Parse apps associated with current Parse account
31+
logs Prints out recent log messages
32+
new Creates a new Parse app and adds Cloud Code to an existing Parse app
33+
releases Gets the releases for a Parse app
34+
rollback Rolls back the version for the given app
35+
symbols Uploads symbol files
36+
triggers Lists Cloud Code triggers and trigger webhooks
37+
update Updates this tool to the latest version
38+
version Gets the Command Line Tools version
39+
help Help about any command
40+
```

Resources/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.android.app"
4+
android:versionCode="2778"
5+
android:versionName="1.1" >
6+
7+
</manifest>

Resources/Test.xcarchive/Info.plist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>ApplicationProperties</key>
6+
<dict>
7+
<key>ApplicationPath</key>
8+
<string>Applications/Test.app</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.facebook.Test</string>
11+
<key>CFBundleShortVersionString</key>
12+
<string>1.0</string>
13+
<key>CFBundleVersion</key>
14+
<string>1.0</string>
15+
<key>SigningIdentity</key>
16+
<string>iPhone Developer: Nikita Lutsenko (8KB4VANCMF)</string>
17+
</dict>
18+
<key>ArchiveVersion</key>
19+
<integer>2</integer>
20+
<key>CreationDate</key>
21+
<date>2014-08-04T19:46:06Z</date>
22+
<key>Name</key>
23+
<string>Test</string>
24+
<key>SchemeName</key>
25+
<string>Test</string>
26+
</dict>
27+
</plist>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.apple.xcode.dsym.com.facebook.Test</string>
9+
<key>CFBundleInfoDictionaryVersion</key>
10+
<string>6.0</string>
11+
<key>CFBundlePackageType</key>
12+
<string>dSYM</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleVersion</key>
18+
<string>1.0</string>
19+
</dict>
20+
</plist>
Binary file not shown.

Resources/build_tools/.empty

Whitespace-only changes.

Resources/mapping.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#such

add_cmd.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/facebookgo/stackerr"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
type addCmd struct {
12+
MakeDefault bool
13+
apps *apps
14+
}
15+
16+
func (a *addCmd) writeConfig(
17+
app *app,
18+
args []string,
19+
e *env,
20+
verbose bool,
21+
) error {
22+
config, err := configFromDir(e.Root)
23+
if err != nil {
24+
return err
25+
}
26+
27+
p := config.getProjectConfig()
28+
if p.Type == legacy {
29+
parseConfig, ok := config.(*parseConfig)
30+
if !ok {
31+
return stackerr.New("Invalid Cloud Code config.")
32+
}
33+
return a.writeParseConfig(parseConfig, app, args, e, verbose)
34+
}
35+
36+
return stackerr.Newf("Unknown project type: %s.", p.Type)
37+
}
38+
39+
func (a *addCmd) selectApp(e *env) (*app, error) {
40+
apps, err := a.apps.restFetchApps(e)
41+
if err != nil {
42+
return nil, err
43+
}
44+
app, err := a.apps.selectApp(apps, "Select an App to add to config: ", e)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return app, nil
49+
}
50+
51+
func (a *addCmd) run(e *env, args []string) error {
52+
_, err := os.Lstat(filepath.Join(e.Root, legacyConfigFile))
53+
if os.IsNotExist(err) {
54+
return stackerr.New("Please run add command inside a parse project.")
55+
}
56+
if err := a.apps.login.authUser(e); err != nil {
57+
return err
58+
}
59+
app, err := a.selectApp(e)
60+
if err != nil {
61+
return err
62+
}
63+
return a.writeConfig(app, args, e, true)
64+
}
65+
66+
func newAddCmd(e *env) *cobra.Command {
67+
a := &addCmd{
68+
MakeDefault: false,
69+
apps: &apps{},
70+
}
71+
cmd := &cobra.Command{
72+
Use: "add [app]",
73+
Short: "Adds a new Parse App to config in current Cloud Code directory",
74+
Long: `Adds a new Parse App to config in current Cloud Code directory.
75+
If an argument is given, the added application can also be referenced by that name.`,
76+
Run: runWithArgs(e, a.run),
77+
}
78+
cmd.Flags().BoolVarP(&a.MakeDefault, "default", "d", a.MakeDefault,
79+
"Make the selected app default")
80+
return cmd
81+
}

add_cmd_parse.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/facebookgo/stackerr"
7+
)
8+
9+
func (a *addCmd) writeParseConfig(
10+
parseConfig *parseConfig,
11+
app *app,
12+
args []string,
13+
e *env,
14+
verbose bool,
15+
) error {
16+
// add app to config
17+
if _, ok := parseConfig.Applications[app.Name]; ok {
18+
return stackerr.Newf("App %s has already been added", app.Name)
19+
}
20+
parseConfig.Applications[app.Name] = &parseAppConfig{
21+
ApplicationID: app.ApplicationID,
22+
MasterKey: app.MasterKey,
23+
}
24+
25+
if len(args) > 0 && args[0] != "" {
26+
alias := args[0]
27+
aliasConfig, ok := parseConfig.Applications[alias]
28+
if !ok {
29+
parseConfig.Applications[alias] = &parseAppConfig{Link: app.Name}
30+
}
31+
if ok && aliasConfig.getLink() != "" {
32+
fmt.Fprintf(e.Out, "Overwriting alias: %q to point to %q\n", alias, app.Name)
33+
parseConfig.Applications[alias] = &parseAppConfig{Link: app.Name}
34+
}
35+
}
36+
37+
if a.MakeDefault {
38+
if _, ok := parseConfig.Applications[defaultKey]; ok {
39+
return stackerr.New(`Default key already set. To override default, use command "parse default"`)
40+
}
41+
parseConfig.Applications[defaultKey] = &parseAppConfig{Link: app.Name}
42+
}
43+
44+
if err := storeParseConfig(e, parseConfig); err != nil {
45+
return err
46+
}
47+
if verbose {
48+
fmt.Fprintf(e.Out, "Written config for %q\n", app.Name)
49+
if a.MakeDefault {
50+
fmt.Fprintf(e.Out, "Set %q as default\n", app.Name)
51+
}
52+
}
53+
54+
return nil
55+
}

add_cmd_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
11+
"github.com/facebookgo/ensure"
12+
"github.com/facebookgo/parse"
13+
)
14+
15+
func newAddCmdHarness(t testing.TB) (*Harness, []*app) {
16+
h := newHarness(t)
17+
defer h.Stop()
18+
apps := []*app{
19+
{
20+
Name: "A",
21+
ApplicationID: "appId.A",
22+
MasterKey: "masterKey.A",
23+
},
24+
{
25+
Name: "B",
26+
ApplicationID: "appId.B",
27+
MasterKey: "masterKey.B",
28+
},
29+
}
30+
res := map[string][]*app{"results": apps}
31+
ht := transportFunc(func(r *http.Request) (*http.Response, error) {
32+
ensure.DeepEqual(t, r.URL.Path, "/1/apps")
33+
email, password := r.Header.Get("X-Parse-Email"), r.Header.Get("X-Parse-Password")
34+
if email == "email" && password == "password" {
35+
return &http.Response{
36+
StatusCode: http.StatusOK,
37+
Body: ioutil.NopCloser(strings.NewReader(jsonStr(t, &res))),
38+
}, nil
39+
}
40+
return &http.Response{
41+
StatusCode: http.StatusUnauthorized,
42+
Body: ioutil.NopCloser(strings.NewReader(`{"error": "incorrect username / password"}`)),
43+
}, nil
44+
})
45+
h.env.Client = &Client{client: &parse.Client{Transport: ht}}
46+
return h, apps
47+
}
48+
49+
func newAddCmdHarnessWithConfig(t testing.TB) (*Harness, *addCmd, error) {
50+
a := addCmd{apps: &defaultApps}
51+
52+
h, _ := newAddCmdHarness(t)
53+
h.makeEmptyRoot()
54+
55+
if err := os.MkdirAll(filepath.Join(h.env.Root, configDir), 0755); err != nil {
56+
return nil, nil, err
57+
}
58+
59+
if err := ioutil.WriteFile(
60+
filepath.Join(h.env.Root, legacyConfigFile),
61+
[]byte("{}"),
62+
0600); err != nil {
63+
return nil, nil, err
64+
}
65+
66+
return h, &a, nil
67+
}
68+
69+
func TestAddCmdGlobalMakeDefault(t *testing.T) {
70+
t.Parallel()
71+
h, a, err := newAddCmdHarnessWithConfig(t)
72+
defer h.Stop()
73+
a.MakeDefault = true
74+
ensure.Nil(t, err)
75+
h.env.In = ioutil.NopCloser(strings.NewReader("1\n"))
76+
ensure.Nil(t, a.run(h.env, []string{}))
77+
}
78+
79+
func TestAddCmdGlobalNotDefault(t *testing.T) {
80+
t.Parallel()
81+
h, a, err := newAddCmdHarnessWithConfig(t)
82+
defer h.Stop()
83+
ensure.Nil(t, err)
84+
h.env.In = ioutil.NopCloser(strings.NewReader("1\n"))
85+
ensure.Nil(t, a.run(h.env, []string{}))
86+
}

0 commit comments

Comments
 (0)