Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
8f607f2d
Commit
8f607f2d
authored
8 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] `reset` modularized
parent
fb73ef6b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/cli.js
+0
-74
0 additions, 74 deletions
app/cli.js
app/modules/reset.js
+48
-0
48 additions, 0 deletions
app/modules/reset.js
index.js
+2
-0
2 additions, 0 deletions
index.js
with
50 additions
and
74 deletions
app/cli.js
+
0
−
74
View file @
8f607f2d
...
...
@@ -269,44 +269,6 @@ module.exports = () => {
})
})));
program
.
command
(
'
reset [config|data|peers|tx|stats|all]
'
)
.
description
(
'
Reset configuration, data, peers, transactions or everything in the database
'
)
.
action
(
subCommand
((
type
)
=>
{
let
init
=
[
'
data
'
,
'
all
'
].
indexOf
(
type
)
!==
-
1
?
getServer
.
bind
(
getServer
,
program
)
:
connect
;
return
init
(
function
(
server
)
{
if
(
!~
[
'
config
'
,
'
data
'
,
'
peers
'
,
'
stats
'
,
'
all
'
].
indexOf
(
type
))
{
throw
constants
.
ERRORS
.
CLI_CALLERR_RESET
;
}
return
co
(
function
*
()
{
try
{
if
(
type
==
'
data
'
)
{
yield
server
.
resetData
();
logger
.
warn
(
'
Data successfully reseted.
'
);
}
if
(
type
==
'
peers
'
)
{
yield
server
.
resetPeers
();
logger
.
warn
(
'
Peers successfully reseted.
'
);
}
if
(
type
==
'
stats
'
)
{
yield
server
.
resetStats
();
logger
.
warn
(
'
Stats successfully reseted.
'
);
}
if
(
type
==
'
config
'
)
{
yield
server
.
resetConf
();
logger
.
warn
(
'
Configuration successfully reseted.
'
);
}
if
(
type
==
'
all
'
)
{
yield
server
.
resetAll
();
logger
.
warn
(
'
Data & Configuration successfully reseted.
'
);
}
}
catch
(
e
)
{
logger
.
error
(
e
);
}
});
},
type
!=
'
peers
'
)(
type
);
}));
program
.
on
(
'
*
'
,
function
(
cmd
)
{
console
.
log
(
"
Unknown command '%s'. Try --help for a listing of commands & options.
"
,
cmd
);
...
...
@@ -331,42 +293,6 @@ module.exports = () => {
};
}
function
connect
(
callback
,
useDefaultConf
)
{
return
function
()
{
const
cbArgs
=
arguments
;
const
dbName
=
program
.
mdb
||
"
duniter_default
"
;
const
dbHome
=
program
.
home
;
const
home
=
directory
.
getHome
(
dbName
,
dbHome
);
const
theServer
=
duniter
(
home
,
program
.
memory
===
true
,
commandLineConf
(
program
));
// If ever the process gets interrupted
let
isSaving
=
false
;
closeCommand
=
()
=>
co
(
function
*
()
{
if
(
!
isSaving
)
{
isSaving
=
true
;
// Save DB
return
theServer
.
disconnect
();
}
});
// Initialize server (db connection, ...)
return
theServer
.
plugFileSystem
(
useDefaultConf
)
.
then
(()
=>
theServer
.
loadConf
())
.
then
(
function
()
{
try
{
cbArgs
.
length
--
;
cbArgs
[
cbArgs
.
length
++
]
=
theServer
;
cbArgs
[
cbArgs
.
length
++
]
=
theServer
.
conf
;
return
callback
.
apply
(
this
,
cbArgs
);
}
catch
(
e
)
{
theServer
.
disconnect
();
throw
e
;
}
});
};
}
function
service
(
callback
,
nologs
)
{
return
function
()
{
...
...
This diff is collapsed.
Click to expand it.
app/modules/reset.js
0 → 100644
+
48
−
0
View file @
8f607f2d
"
use strict
"
;
const
co
=
require
(
'
co
'
);
const
constants
=
require
(
'
../lib/constants
'
);
const
wizard
=
require
(
'
../lib/wizard
'
);
const
logger
=
require
(
'
../lib/logger
'
)(
'
wizard
'
);
module
.
exports
=
{
duniter
:
{
cli
:
[{
name
:
'
reset [config|data|peers|tx|stats|all]
'
,
desc
:
'
Reset configuration, data, peers, transactions or everything in the database
'
,
onConfiguredExecute
:
(
server
,
conf
,
program
,
params
,
wizardTasks
)
=>
co
(
function
*
()
{
const
type
=
params
[
0
];
if
(
type
===
'
peers
'
)
{
// Needs the DAL plugged
yield
server
.
initDAL
();
}
switch
(
type
)
{
case
'
data
'
:
yield
server
.
resetData
();
logger
.
warn
(
'
Data successfully reseted.
'
);
break
;
case
'
peers
'
:
yield
server
.
resetPeers
();
logger
.
warn
(
'
Peers successfully reseted.
'
);
break
;
case
'
stats
'
:
yield
server
.
resetStats
();
logger
.
warn
(
'
Stats successfully reseted.
'
);
break
;
case
'
config
'
:
yield
server
.
resetConf
();
logger
.
warn
(
'
Configuration successfully reseted.
'
);
break
;
case
'
all
'
:
yield
server
.
resetAll
();
logger
.
warn
(
'
Data & Configuration successfully reseted.
'
);
break
;
default
:
throw
constants
.
ERRORS
.
CLI_CALLERR_RESET
;
}
})
}]
}
};
This diff is collapsed.
Click to expand it.
index.js
+
2
−
0
View file @
8f607f2d
...
...
@@ -16,6 +16,7 @@ const configDependency = require('./app/modules/config');
const
wizardDependency
=
require
(
'
./app/modules/wizard
'
);
const
genDependency
=
require
(
'
./app/modules/gen
'
);
const
syncDependency
=
require
(
'
./app/modules/synchronization
'
);
const
resetDependency
=
require
(
'
./app/modules/reset
'
);
const
MINIMAL_DEPENDENCIES
=
[
{
name
:
'
duniter-config
'
,
required
:
configDependency
}
...
...
@@ -26,6 +27,7 @@ const DEFAULT_DEPENDENCIES = [
{
name
:
'
duniter-sync
'
,
required
:
syncDependency
},
{
name
:
'
duniter-wizard
'
,
required
:
wizardDependency
},
{
name
:
'
duniter-gen
'
,
required
:
genDependency
},
{
name
:
'
duniter-reset
'
,
required
:
resetDependency
},
{
name
:
'
duniter-keypair
'
,
required
:
dkeypairDependency
}
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment