Skip to content

Commit

Permalink
refactor internal modules (#149)
Browse files Browse the repository at this point in the history
should
- close #85
 
## description
### before
```
pkgs/nu-git-manager/
|-- nu-git-manager
|   |-- completions
|   |   `-- nu-complete.nu
|   |-- error
|   |   `-- error.nu
|   |-- fs
|   |   |-- cache.nu
|   |   |-- dir.nu
|   |   |-- path.nu
|   |   `-- store.nu
|   |-- git
|   |   |-- repo.nu
|   |   `-- url.nu
|   `-- mod.nu
|-- nupm.nuon
`-- tests
    |-- gm.nu
    `-- mod.nu
```
```
pkgs/nu-git-manager-sugar/
|-- nu-git-manager-sugar
|   |-- completions
|   |   `-- nu-complete.nu
|   |-- extra.nu
|   |-- git
|   |   |-- lib
|   |   |   |-- lib.nu
|   |   |   |-- prompt.nu
|   |   |   `-- style.nu
|   |   |-- mod.nu
|   |   `-- prompt.nu
|   |-- github.nu
|   `-- mod.nu
|-- nupm.nuon
`-- tests
    |-- git.nu
    `-- mod.nu
```

### after
> **Important**
>  caveats:
> - `[1]`: has `use path.nu ...` instead of `use path`
> - `[2]`: has `use style.nu ...` instead of `use style`

```
pkgs/nu-git-manager/
|-- nu-git-manager
|   |-- completions.nu    # internal
|   |-- error.nu          # internal
|   |-- fs                # internal
|   |   |-- cache.nu   [1]
|   |   |-- dir.nu     [1]
|   |   |-- mod.nu
|   |   |-- path.nu
|   |   `-- store.nu   [1]
|   |-- git               # internal
|   |   |-- mod.nu
|   |   |-- repo.nu
|   |   `-- url.nu
|   `-- mod.nu
|-- nupm.nuon
`-- tests
    |-- gm.nu
    `-- mod.nu
```
```
pkgs/nu-git-manager-sugar/
|-- nu-git-manager-sugar
|   |-- completions.nu        # internal
|   |-- extra.nu              # public
|   |-- git                   # public
|   |   |-- lib               #     internal
|   |   |   |-- git.nu     [2]#         public
|   |   |   |-- mod.nu
|   |   |   |-- prompt.nu     #         public
|   |   |   `-- style.nu   [2]#         public
|   |   |-- mod.nu
|   |   `-- prompt.nu         #     public
|   |-- github.nu             # public
|   `-- mod.nu
|-- nupm.nuon
`-- tests
    |-- git.nu
    `-- mod.nu
```

## TODO
- [x] `nu-git-manager-sugar/git/lib` issue with `prompt.nu` in
77596ff
  • Loading branch information
amtoine authored Dec 18, 2023
1 parent 8dd94f3 commit cb591b8
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ../../git/lib/style.nu [color]
use style.nu [color]

# give the revision of the repo you're in
#
Expand Down Expand Up @@ -119,3 +119,4 @@ export def get-status [
untracked: ($status | parse --regex '^\?\? (?<file>.*)' | get file),
}
}

3 changes: 3 additions & 0 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export module git.nu
export module prompt.nu
export module style.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ../../git/lib/lib.nu [get-revision, git-action, get-status]
use ../../git/lib/style.nu [color, simplify-path]
use git [get-revision, git-action, get-status]
use style.nu [color, simplify-path]

# /!\ the PWD will be sanitized
export def get-left-prompt [duration_threshold: duration]: nothing -> string {
Expand Down
5 changes: 3 additions & 2 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std log

use ../git/lib/lib.nu [get-status]
module lib/
use lib git [get-status]

use ../completions/nu-complete.nu [
use completions [
GIT_QUERY_TABLES, GIT_STRATEGIES, git-query-tables, get-remotes, get-branches, get-strategies
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ../git/lib/prompt.nu [get-left-prompt]
use lib prompt [get-left-prompt]

const DEFAULT_PROMPT_INDICATORS = {
plain: "> ",
Expand Down
3 changes: 2 additions & 1 deletion pkgs/nu-git-manager-sugar/nu-git-manager-sugar/mod.nu
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module completions.nu
export module extra.nu
export module git
export module git/
export module github.nu
8 changes: 4 additions & 4 deletions pkgs/nu-git-manager-sugar/tests/git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/ git [
"gm repo branch wipe"
"gm repo compare"
]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs/path.nu ["path sanitize"]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs path ["path sanitize"]
use ../../../tests/common/setup.nu [get-random-test-dir]

def --env init-repo-and-cd-into []: nothing -> path {
Expand Down Expand Up @@ -354,13 +354,13 @@ export def branch-compare [] {
}

export module prompt {
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib/lib.nu [
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib git [
get-revision, git-action
]
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib/prompt.nu [
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib prompt [
get-left-prompt
]
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib/style.nu [
use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/lib style [
simplify-path
]

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion pkgs/nu-git-manager/nu-git-manager/fs/cache.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use path.nu "path sanitize"
use ../git/repo.nu [is-grafted]

# get the path to the cache of the local store of repos
#
Expand Down
4 changes: 4 additions & 0 deletions pkgs/nu-git-manager/nu-git-manager/fs/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export module cache.nu
export module dir.nu
export module path.nu
export module store.nu
2 changes: 2 additions & 0 deletions pkgs/nu-git-manager/nu-git-manager/git/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export module repo.nu
export module url.nu
2 changes: 1 addition & 1 deletion pkgs/nu-git-manager/nu-git-manager/git/repo.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ../error/error.nu [throw-error]
use ../error.nu [throw-error]

# tell if a local repository has been grafted
#
Expand Down
2 changes: 1 addition & 1 deletion pkgs/nu-git-manager/nu-git-manager/git/url.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ../fs/path.nu "path sanitize"
use ../fs path "path sanitize"

# parse the URL of a Git repo
#
Expand Down
25 changes: 15 additions & 10 deletions pkgs/nu-git-manager/nu-git-manager/mod.nu
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use std log

use fs/store.nu [get-repo-store-path, list-repos-in-store]
use fs/cache.nu [
module completions.nu
module error.nu
module fs/
module git/

use fs store [get-repo-store-path, list-repos-in-store]
use fs cache [
get-repo-store-cache-path, check-cache-file, add-to-cache, remove-from-cache, open-cache,
save-cache, clean-cache-dir
]
use fs/dir.nu [clean-empty-directories-rec]
use fs/path.nu ["path sanitize", "path remove-prefix"]
use git/url.nu [parse-git-url, get-fetch-push-urls]
use git/repo.nu [is-grafted, get-root-commit, list-remotes]
use error/error.nu [throw-error, throw-warning]
use fs dir [clean-empty-directories-rec]
use fs path ["path sanitize", "path remove-prefix"]
use git url [parse-git-url, get-fetch-push-urls]
use git repo [is-grafted, get-root-commit, list-remotes]
use error.nu [throw-error, throw-warning]

use completions/nu-complete.nu
use completions

# manage your Git repositories with the main command of NGM
#
Expand Down Expand Up @@ -84,8 +89,8 @@ export def "gm clone" [
url: string # the URL to the repository to clone, supports HTTPS and SSH links, as well as references ending in `.git` or starting with `git@`
--remote: string = "origin" # the name of the remote to setup
--ssh # setup the remote to use the SSH protocol both to FETCH and to PUSH
--fetch: string@"nu-complete git-protocols" # setup the FETCH protocol explicitely, will overwrite `--ssh` for FETCH
--push: string@"nu-complete git-protocols" # setup the PUSH protocol explicitely, will overwrite `--ssh` for PUSH
--fetch: string@"completions git-protocols" # setup the FETCH protocol explicitely, will overwrite `--ssh` for FETCH
--push: string@"completions git-protocols" # setup the PUSH protocol explicitely, will overwrite `--ssh` for PUSH
--bare # clone the repository as a "bare" project
--depth: int # the depth at which to clone the repository
]: nothing -> nothing {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/nu-git-manager/tests/gm.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std assert

use ../../../pkgs/nu-git-manager/nu-git-manager/fs/path.nu ["path sanitize"]
use ../../../pkgs/nu-git-manager/nu-git-manager/git/repo.nu [list-remotes]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs path ["path sanitize"]
use ../../../pkgs/nu-git-manager/nu-git-manager/git repo [list-remotes]
use ../../../pkgs/nu-git-manager/nu-git-manager/ *

use ../../../tests/common/setup.nu [get-random-test-dir]
Expand Down
12 changes: 6 additions & 6 deletions pkgs/nu-git-manager/tests/mod.nu
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use std assert

use ../../../pkgs/nu-git-manager/nu-git-manager/git/url.nu [
use ../../../pkgs/nu-git-manager/nu-git-manager/git url [
parse-git-url, get-fetch-push-urls
]
use ../../../pkgs/nu-git-manager/nu-git-manager/git/repo.nu [
use ../../../pkgs/nu-git-manager/nu-git-manager/git repo [
is-grafted, get-root-commit, list-remotes
]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs/store.nu [
use ../../../pkgs/nu-git-manager/nu-git-manager/fs store [
get-repo-store-path, list-repos-in-store
]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs/cache.nu [
use ../../../pkgs/nu-git-manager/nu-git-manager/fs cache [
get-repo-store-cache-path, check-cache-file, add-to-cache, remove-from-cache, open-cache,
save-cache, clean-cache-dir
]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs/path.nu [
use ../../../pkgs/nu-git-manager/nu-git-manager/fs path [
"path sanitize", "path remove-prefix", "path remove-trailing-path-sep"
]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs/dir.nu [clean-empty-directories-rec]
use ../../../pkgs/nu-git-manager/nu-git-manager/fs dir [clean-empty-directories-rec]

use ../../../tests/common/setup.nu [get-random-test-dir]

Expand Down
2 changes: 1 addition & 1 deletion tests/common/setup.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ../../pkgs/nu-git-manager/nu-git-manager/fs/path.nu ["path sanitize"]
use ../../pkgs/nu-git-manager/nu-git-manager/fs path ["path sanitize"]

# return the path to a random test directory
#
Expand Down

0 comments on commit cb591b8

Please sign in to comment.